BAEL-3689: Add missing code examples (#10282)
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.startup;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppStartupRunner implements ApplicationRunner {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppStartupRunner.class);
|
||||
public static int counter;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
LOG.info("Application started with option names : {}", args.getOptionNames());
|
||||
LOG.info("Increment counter");
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.startup;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CommandLineAppStartupRunner implements CommandLineRunner {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CommandLineAppStartupRunner.class);
|
||||
public static int counter;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
LOG.info("Increment counter");
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
+6
@@ -1,9 +1,15 @@
|
||||
package com.baeldung.startup;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.startup")
|
||||
public class SpringStartupConfig {
|
||||
|
||||
@Bean(initMethod="init")
|
||||
public InitMethodExampleBean initMethodExampleBean() {
|
||||
return new InitMethodExampleBean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user