Aug 1st, 2011, 01:37 AM
[Fixed]How to get ApplicationContext loaded before servlet listener init in SpirngMVC
Sorry, already fixed!It's related to Context hierarchy in Spring Web MVC which can be found in Springframework's reference document.
I have one Servlet Listener which does some data init work when application launch, but it need the spring ApplicationContext when executing (for example do data check and insert data), so the problem is how to init our spring ApplicationContext before one servlet listener executing?
As the servlet specification, one listener is executed before one servlet startup.
If I don't use springMVC, I can use spring's ContextLoaderListener as my first listener and make it init spring ApplicationContext before other listener init.
But now we already use springMVC3 which has to init applicationContext with one servlet(not listener) - "org.springframework.web.servlet.DispatcherServlet ". So the applicationContext will be inited after my listener.
We tried to add spring "ContextLoaderListener" in web.xml like before, it worked! We get spring ApplicationContext init before our listener, but when the "org.springframework.web.servlet.DispatcherServlet " launched it reloaded spring ApplicationContext again, so the work duplicated!
Any better idea? And we don't want to use spring MVC intercepter and ApplicationContextListener or ApplicationContextEvent ....
Last edited by javeer; Aug 1st, 2011 at 02:28 AM.
Tags for this Thread