美文网首页
springboot2.2.6.RELEASE chapter7

springboot2.2.6.RELEASE chapter7

作者: 淼哥1986 | 来源:发表于2020-04-04 00:09 被阅读0次

Application events are sent in the following order, as your application runs:

  1. An ApplicationStartingEvent is sent at the start of a run but before any processing, except for
    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 ApplicationContextInitializedEvent is sent when the ApplicationContext is prepared and
    ApplicationContextInitializers have been called but before any bean definitions are loaded.
  4. An ApplicationPreparedEvent is sent just before the refresh is started but after bean definitions
    have been loaded.
  5. An ApplicationStartedEvent is sent after the context has been refreshed but before any
    application and command-line runners have been called.
  6. An ApplicationReadyEvent is sent after any application and command-line runners have been
    called. It indicates that the application is ready to service requests.
    50
  7. An ApplicationFailedEvent is sent

example:
Listener

public class ApplicationPreparedEventListener implements ApplicationListener<ApplicationPreparedEvent> {
    public void onApplicationEvent(ApplicationPreparedEvent event) {
        System.out.println("......ApplicationPreparedEvent......");
    }
}

Main

    public static void main(String[] args) {
//        SpringApplication.run(DemoApplication.class, args);
        SpringApplication springApplication = new SpringApplication(DemoApplication.class);
        springApplication.addListeners(new ApplicationPreparedEventListener());
        springApplication.run(args);
    }

输出:

2020-04-04 00:07:15.888  INFO 9672 --- [           main] com.github.examples.DemoApplication      : Starting DemoApplication on DESKTOP-GLVVPCF with PID 9672 (D:\03github\springboot2-learning\chapter3\target\classes started by limiao in D:\03github\springboot2-learning)
2020-04-04 00:07:15.910  INFO 9672 --- [           main] com.github.examples.DemoApplication      : No active profile set, falling back to default profiles: default
......ApplicationPreparedEvent......
2020-04-04 00:07:18.364  INFO 9672 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-04-04 00:07:18.383  INFO 9672 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-04 00:07:18.384  INFO 9672 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-04 00:07:18.544  INFO 9672 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-04 00:07:18.544  INFO 9672 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2457 ms
2020-04-04 00:07:18.906  INFO 9672 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-04 00:07:19.011  INFO 9672 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [public/index.html]
2020-04-04 00:07:19.202  INFO 9672 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-04 00:07:19.207  INFO 9672 --- [           main] com.github.examples.DemoApplication      : Started DemoApplication in 4.214 seconds (JVM running for 6.12)

相关文章

网友评论

      本文标题:springboot2.2.6.RELEASE chapter7

      本文链接:https://www.haomeiwen.com/subject/okrrphtx.html