springboot关于容器启动事件总结

  

在springboot容器启动时,我们需要在启动过程中做一些操作,比如启动容器后,执行某些代码。

  

春提供了监听器,我们可以方便的实现这些操作。

  

在容器启动开始时:

        包com.neo.filter;      进口org.springframework.boot.context.event.ApplicationStartingEvent;   进口org.springframework.context.ApplicationListener;      公共类ApplicationStartingEventListener实现ApplicationListener{   @Override   公共空间>   包com.neo.filter;      进口org.springframework.boot.context.event.ApplicationStartedEvent;   进口org.springframework.context.ApplicationListener;   进口org.springframework.core.Ordered;      公共类ApplicationStartedEventListener实现ApplicationListener命令{      @Override   公共空间>   包com;         进口org.springframework.boot.SpringApplication;   进口org.springframework.boot.autoconfigure.SpringBootApplication;      进口com.neo.filter.ApplicationStartedEventListener;   进口com.neo.filter.ApplicationStartedEventListener2;   进口com.neo.filter.ApplicationStartingEventListener;      @SpringBootApplication   公开课DemoApplication {      公共静态void main (String [] args) {   SpringApplication应用=new SpringApplication (DemoApplication.class);   app.addListeners(新ApplicationStartedEventListener ());   app.addListeners(新ApplicationStartingEventListener ());   app.addListeners(新ApplicationStartedEventListener2 ());   app.run (args);   }   }      

以上就是关于springboot容器启动事件的相关知识点以及实例代码,感谢大家对的支持。

springboot关于容器启动事件总结