How spring containers are executed after initialization

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.