BAEL-3689: Add missing code examples (#10282)

This commit is contained in:
kwoyke 2020-11-27 11:22:00 +01:00 committed by GitHub
parent 10ba4efce6
commit 83535bf123
5 changed files with 15 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
@Component
public class AppStartupRunner implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(AppStartupRunner.class);
public static int counter;

View File

@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
@Component
public class CommandLineAppStartupRunner implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(CommandLineAppStartupRunner.class);
public static int counter;
@ -15,4 +16,4 @@ public class CommandLineAppStartupRunner implements CommandLineRunner {
LOG.info("Increment counter");
counter++;
}
}
}

View File

@ -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();
}
}

View File

@ -37,6 +37,11 @@ public class SpringStartupIntegrationTest {
ctx.getBean(InitializingBeanExampleBean.class);
}
@Test
public void whenInitMethod_shouldLogEnv() throws Exception {
ctx.getBean(InitMethodExampleBean.class);
}
@Test
public void whenApplicationListener_shouldRunOnce() throws Exception {
Assertions.assertThat(StartupApplicationListenerExample.counter).isEqualTo(1);

View File

@ -15,7 +15,7 @@ public class SpringStartupXMLConfigIntegrationTest {
private ApplicationContext ctx;
@Test
public void whenPostConstruct_shouldLogEnv() throws Exception {
public void whenInitMethod_shouldLogEnv() throws Exception {
ctx.getBean(InitMethodExampleBean.class);
}