当前位置:网站首页>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)
边栏推荐
- 宇宙第一 IDE 霸主,换人了。。。
- Team members participate in 2022 China multimedia conference
- If Yi Lijing spits about programmers
- Special Lecture 3 number theory + game theory learning experience (should be updated for a long time)
- Dev gridcontrol 捕获按键事件
- QT note 2
- Kotlin中room数据库的使用
- Official Oracle document
- Kotlin operator
- Shell programming
猜你喜欢

2022-7-5 personal qualifying 2 competition experience

为什么要在时钟输出上预留电容的工位?

BGP routing principle

QT note 1

Write common API tools swagger and redoc

Burp suite Chapter 4 advanced options for SSL and proxy

Daily Note (11) -- word formula input arbitrary matrix

【EndNote】文献模板编排语法详解

【C语言】程序员筑基功法——《函数栈帧的创建与销毁》

Uninstallation of dual systems
随机推荐
22-07-16 personal training match 3 competition experience
日常一记(11)--word公式输入任意矩阵
随机分布学习笔记
The second lesson is the construction of development environment
Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
Shell programming
vim跨行匹配搜索
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
mysql函数汇总之条件判断函数
22-07-12 personal training match 1 competition experience
Differences and connections of previewkeydown, Keydown, keypress and Keyup in C WinForm
BGP routing principle
awk作业
shell编程
Function default parameters, arrow functions, and remaining parameters in ES6 - explanation
[June 29, 2022] examination summary
QSS add resource file of QT
On some concepts involved in journal papers compilation + journal query methods
CV learning notes (optical flow)
vscode 实用快捷键