In the project, you will encounter the need to do some initialization when the container is finished loading, such as quartz listener re-registration (quartz listener in RAM, Web container Restart or shutdown is lost).
<span style= "Font-family:microsoft yahei;font-size:18px;" >import Org.springframework.context.applicationlistener;import Org.springframework.context.event.contextrefreshedevent;public class Initialschedulerlistner Implements applicationlistener<contextrefreshedevent> { </span><span style= "font-family: ' Microsoft YaHei ' ; font-size:18px; " ></span>
<span style= "Font-family:microsoft yahei;font-size:18px;" > @Override public void Onapplicationevent (Contextrefreshedevent event) {</span>
<span style= "Font-family:microsoft yahei;font-size:18px;" > //<span style= "Color:rgb (Wuyi, Wuyi, Wuyi); line-height:25.2000007629395px;" > In a Web project, there are two containers in the system, one root application context and the other the Projectname-servlet context of the project (Root application context sub-container) </span></span>
<span style= "Font-family:microsoft yahei;font-size:18px;" ></span><pre name= "code" class= "java" ><span style= "Font-family:microsoft yahei;font-size:18px;" > //Return The parent context, or <code>null</code> if there is no parent and this is the root of the Context Hierarchy</span>
if (Event.getapplicationcontext (). getParent () = = null) {//ensures that the container executes only once: try {//business logic} catch (Exception e) {}}}}
after the code is written, remember to inject to spring management:
<span style= "Font-family:microsoft yahei;font-size:18px;" ><bean class= "com.wenniuwuren.*. Initialschedulerlistner "/></span>
How spring containers are executed after initialization