I defined a simple SpringApplicationRunListener
implementation with the following method:
@Override
public void finished(ConfigurableApplicationContext configurableApplicationContext, Throwable throwable) {
logger.info("It's finished");
}
When I run without any Spring cloud dependency I get the following log:
2016-04-27 10:37:37.702 INFO 5720 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-27 10:37:37.703 INFO 5720 --- [ main] b.a.test.LazyFilterRuntimeListener : It's finished
However, when I add the following dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Then the "It's finished" line is logged twice, once at the end (like without Spring cloud/Eureka) and once at the start, even before the Spring boot logo appears:
2016-04-27 10:37:35.500 INFO 5720 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@255b53dc: startup date [Wed Apr 27 10:37:35 CEST 2016]; root of context hierarchy
2016-04-27 10:37:35.638 INFO 5720 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-04-27 10:37:35.785 INFO 5720 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'encrypt.CONFIGURATION_PROPERTIES' of type [class org.springframework.cloud.bootstrap.encrypt.KeyProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-27 10:37:35.786 INFO 5720 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'encryptionBootstrapConfiguration' of type [class org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$$EnhancerBySpringCGLIB$$268d5fc8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-27 10:37:35.839 INFO 5720 --- [ main] b.c.test.LazyFilterRuntimeListener : It's finished
2016-04-27 10:37:35.842 INFO 5720 --- [ main] be.company.test.TestApplication : Started TestApplication in 0.499 seconds (JVM running for 0.86)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.7.RELEASE)
...
2016-04-27 10:37:37.702 INFO 5720 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-27 10:37:37.703 INFO 5720 --- [ main] b.c.test.LazyFilterRuntimeListener : It's finished
2016-04-27 10:37:37.703 INFO 5720 --- [ main] be.company.test.TestApplication : Started TestApplication in 2.423 seconds (JVM running for 2.721)
It also mentions the line "Started Application in ..." twice.
Is there a particular reason for this behaviour? I'm trying to write a SpringApplicationRunListener
that relies on specific beans to have been created. However, if I add spring cloud, the first time it reaches the finished()
method, the context is not yet created, so it currently throws an error.