当前位置:网站首页>23.5 event listeners of application events and listeners
23.5 event listeners of application events and listeners
2022-07-26 08:28:00 【csg103】
Besides using Spring Outside the event of the framework ,SpringApplication Some additional events will also be sent .
Some events are in ApplicationContext It is triggered automatically before generation , For these events , Can not act as @Bean Register listener , Can pass SpringApplication.addListeners(…) or SpringApplicationBuilder.listeners(…) Method .
@SpringBootApplication public class Application { public static void main(String[] args) {SpringApplication application = new SpringApplication(Application.class); application.addListeners(new ApplicationListenerStarted()); application.addListeners(new ApplicationListenerEnvironmentPrepared()); application.addListeners(new ApplicationListenerPrepared()); application.addListeners(new ApplicationListenerReadyEvent()); application.addListeners(new ApplicationListenerFailed()); application.run(args);}} class ApplicationListenerEnvironmentPrepared implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { @Overridepublic void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { System.out.println("--------------------0"+getClass().getSimpleName());}} class ApplicationListenerFailed implements ApplicationListener<ApplicationFailedEvent> { @Overridepublic void onApplicationEvent(ApplicationFailedEvent event) { System.out.println("--------------------1"+getClass().getSimpleName());}} class ApplicationListenerPrepared implements ApplicationListener<ApplicationPreparedEvent> { @Overridepublic void onApplicationEvent(ApplicationPreparedEvent event) { System.out.println("--------------------2"+getClass().getSimpleName());}}class ApplicationListenerStarted implements ApplicationListener<ApplicationStartedEvent> { @Overridepublic void onApplicationEvent(ApplicationStartedEvent event) { System.out.println("--------------------3"+getClass().getSimpleName());}
Execution results
2017-06-10 14:28:43.932 INFO 25636 --- [ restartedMain] com.csg.Application : Started Application in 0.346 seconds (JVM running for 85.356)
2017-06-10 14:29:03.134 INFO 25636 --- [ Thread-18] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot[email protected]1d48ba6f: startup date [Sat Jun 10 14:28:43 CST 2017]; root of context hierarchy
2017-06-10 14:29:03.134 INFO 25636 --- [ Thread-18] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
--------------------0ApplicationListenerStarted
--------------------1ApplicationListenerEnvironmentPrepared
┬┴┬/ ̄\_/ ̄\
┬┴┬┴▏ ▏▔▔▔▔\
┴┬┴/\ / ﹨
┬┴∕ / )
┴┬▏ ● ▏
┬┴▏ ▔█
┴◢██◣ \__/ !
┬█████◣ /
┴█████████████◣
◢██████████████▆▄
█◤◢██◣◥█████████◤\
◥◢████ ████████◤ \
┴█████ ██████◤ ﹨
┬│ │█████◤ ▏
┴│ │ ▏
┬∕ ∕ /▔▔▔\ ∕
┴/___/﹨ ∕ ﹨ /\
# This is springboot Version number of
1.5.4.RELEASE
# This is springboot Version number of
(v1.5.4.RELEASE)
2017-06-10 14:29:03.289 INFO 25636 --- [ restartedMain] com.csg.Application : Starting Application on DESKTOP-F36IHM2 with PID 25636 (J:\work1\target\classes started by csg in J:\work1)
2017-06-10 14:29:03.289 INFO 25636 --- [ restartedMain] com.csg.Application : No active profile set, falling back to default profiles: default
--------------------2ApplicationListenerPrepared
2017-06-10 14:29:03.291 INFO 25636 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]22e8c4f7: startup date [Sat Jun 10 14:29:03 CST 2017]; root of context hierarchy
2017-06-10 14:29:03.460 INFO 25636 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 1111 (http)
2017-06-10 14:29:03.461 INFO 25636 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-06-10 14:29:03.461 INFO 25636 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-06-10 14:29:03.469 INFO 25636 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-10 14:29:03.469 INFO 25636 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 179 ms
2017-06-10 14:29:03.484 INFO 25636 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-10 14:29:03.484 INFO 25636 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-10 14:29:03.484 INFO 25636 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-10 14:29:03.484 INFO 25636 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-10 14:29:03.484 INFO 25636 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-10 14:29:03.515 INFO 25636 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]22e8c4f7: startup date [Sat Jun 10 14:29:03 CST 2017]; root of context hierarchy
2017-06-10 14:29:03.518 INFO 25636 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-10 14:29:03.519 INFO 25636 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-10 14:29:03.523 INFO 25636 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-10 14:29:03.523 INFO 25636 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-10 14:29:03.527 INFO 25636 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-10 14:29:03.536 INFO 25636 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2017-06-10 14:29:03.554 INFO 25636 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-06-10 14:29:03.561 INFO 25636 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1111 (http)
--------------------3ApplicationListenerReadyEvent
2017-06-10 14:29:03.562 INFO 25636 --- [ restartedMain] com.csg.Application : Started Application in 0.292 seconds (JVM running for 104.986)
边栏推荐
- Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
- 【EndNote】文献模板编排语法详解
- memorandum...
- 我,35岁了。
- Kotlin operator
- BGP --- 边界网关协议
- 请问现在flinkcdc支持sqlserver实例名方式连接吗?
- Flex three column layout
- One click deployment lamp and LNMP architecture
- Exam summary on June 27, 2022
猜你喜欢

Basic music theory rhythm connection problem, very important

Kotlin operator

22-07-16 personal training match 3 competition experience

C # get the information of the selected file

Date and time function of MySQL function summary

Burp suite Chapter 9 how to use burp repeater

Basic configuration of BGP

Burp suite Chapter 6 how to use burp spider

2022-7-8 personal qualifying 5 competition experience (supplementary)
![[GUI] swing package (window, pop-up window, label, panel, button, list, text box)](/img/05/8e7483768a4ad2036497cac136b77d.png)
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)
随机推荐
Introduction to arrays -- array
Exam summary on June 27, 2022
Sed job
2022年全国职业院校技能大赛“网络安全”竞赛试题文件上传渗透测试答案Flag
SPSS用KMeans、两阶段聚类、RFM模型在P2P网络金融研究借款人、出款人行为规律数据
Burp suite Chapter 7 how to use burp scanner
宇宙第一 IDE 霸主,换人了。。。
Kotlin program control
awk作业
Two ways to monitor the change of user points
2022-7-6 personal qualifying 3 competition experience
Date and time function of MySQL function summary
Add in the registry right click to open in vscode
Day 3 homework
A little awesome, 130000 a month+
QSS add resource file of QT
Function default parameters, arrow functions, and remaining parameters in ES6 - explanation
mysql函数汇总之条件判断函数
BGP的基本配置
matplotlib学习笔记