This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I need to instantiate a Spring applicationcontext in a Servlet. Is there any best way to do this ?
If the same ApplicationConext needs to be shared among many servlet, what would be the best way ?
Thanks and Regards,
Best way is to use the ContextLoaderListener in your web.xml This will create an ApplicationContext for you when you deploy you war. This app context will be placed in your ServletContext for that app.
Now that code is not 100% compilable, you have to fill in the servletContext variable and my method call might be slightly wrong, but your IDE will tell you what methods are on the ServletContextUtils class.