監聽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事件

相關文章
相關標籤/搜索