After the spring container initialization is complete, call the class Beanpostprocessor, which implements the Applicationlistener interface, overrides the Onapplicationevent method,
The method is the data or cache that we want to load after the container initialization is complete.
Here is the XML configuration:
Here are the Beanpostprocessor classes that you wrote:
Following is the start of Tomcat, repeated loading of data, called two times the Onapplicationevent method:
In the blue section:
Two containers of Root Webapplicationcontext and Webapplicationcontext (Spring-servlet).
The following is the time to initialize the national area information when loaded two times:
Returning JDBC Connection to DataSource has loaded the region information before, and then fetching JDBC Connection from DataSource and loaded again.
Asked the degree Niang: although there are methods, but after the trial still did not solve the problem.
Method One:
Add Judgment in the Onapplicationevent () method,
==null, and then judge the code inside that you want to initialize or cache.
Method Two:
The string value is compared to equals ("Root webapplicationcontext").
Method Three:
Precede the event parameters with final, final, contextrefreshedevent event.
Finally, there is no solution to the problem, perhaps to solve the problem of everyone, write down first.
The onapplicationevent in the Applicationlistener interface is called two times solution