监听Spring Boot的SpringApplication events

META-INF/spring.factories中添加键值对html

org.springframework.context.ApplicationListener=com.example.project.MyListenerspring

其中 MyListener实现org.springframework.context.ApplicationListener接口。app

事件触发时机spring-boot

1. An ApplicationStartedEvent is sent at the start of a run, but before any processing except the
registration of listeners and initializers.
2. An ApplicationEnvironmentPreparedEvent is sent when the Environment to be used in the
context is known, but before the context is created.
3. An ApplicationPreparedEvent is sent just before the refresh is started, but after bean definitions
have been loaded.
4. An ApplicationReadyEvent is sent after the refresh and any related callbacks have been
processed to indicate the application is ready to service requests.
5. An ApplicationFailedEvent is sent if there is an exception on startup.htm

注:此事件非Spring容器内事件。接口

参考:http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-application-events-and-listeners事件

相关文章
相关标签/搜索