BAEL-3689: Add missing code examples (#10282)
This commit is contained in:
parent
10ba4efce6
commit
83535bf123
@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AppStartupRunner implements ApplicationRunner {
|
public class AppStartupRunner implements ApplicationRunner {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AppStartupRunner.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AppStartupRunner.class);
|
||||||
public static int counter;
|
public static int counter;
|
||||||
|
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class CommandLineAppStartupRunner implements CommandLineRunner {
|
public class CommandLineAppStartupRunner implements CommandLineRunner {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CommandLineAppStartupRunner.class);
|
private static final Logger LOG = LoggerFactory.getLogger(CommandLineAppStartupRunner.class);
|
||||||
public static int counter;
|
public static int counter;
|
||||||
|
|
@ -1,9 +1,15 @@
|
|||||||
package com.baeldung.startup;
|
package com.baeldung.startup;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("com.baeldung.startup")
|
@ComponentScan("com.baeldung.startup")
|
||||||
public class SpringStartupConfig {
|
public class SpringStartupConfig {
|
||||||
|
|
||||||
|
@Bean(initMethod="init")
|
||||||
|
public InitMethodExampleBean initMethodExampleBean() {
|
||||||
|
return new InitMethodExampleBean();
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,6 +37,11 @@ public class SpringStartupIntegrationTest {
|
|||||||
ctx.getBean(InitializingBeanExampleBean.class);
|
ctx.getBean(InitializingBeanExampleBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInitMethod_shouldLogEnv() throws Exception {
|
||||||
|
ctx.getBean(InitMethodExampleBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenApplicationListener_shouldRunOnce() throws Exception {
|
public void whenApplicationListener_shouldRunOnce() throws Exception {
|
||||||
Assertions.assertThat(StartupApplicationListenerExample.counter).isEqualTo(1);
|
Assertions.assertThat(StartupApplicationListenerExample.counter).isEqualTo(1);
|
||||||
|
@ -15,7 +15,7 @@ public class SpringStartupXMLConfigIntegrationTest {
|
|||||||
private ApplicationContext ctx;
|
private ApplicationContext ctx;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPostConstruct_shouldLogEnv() throws Exception {
|
public void whenInitMethod_shouldLogEnv() throws Exception {
|
||||||
ctx.getBean(InitMethodExampleBean.class);
|
ctx.getBean(InitMethodExampleBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user