PDA

View Full Version : Any way to get the ApplicationContext if no web framework is used?


dxxvi
Apr 25th, 2007, 10:19 AM
Hello everybody,

Suppose that I use only servlet and jsp in my web application (no web framework, like Struts, JSF ...., is used). Is there any way to get the Spring application context created by the ContextLoaderListener from the value of the contextConfigLocation parameter from each of my new servlets? (Of course, we can add any servlet / listener to the web.xml file or extend the ContextLoaderListener ....).

My first thought is create an abstract servlet where the Spring application context is created with

new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"})

then save this application context in the application scope.

Thanks for any of your ideas.

Andreas Senft
Apr 25th, 2007, 10:34 AM
Are you looking for something like WebApplicationContextUtils.getWebApplicationContex t()?

dxxvi
Apr 25th, 2007, 10:57 AM
:)) Yes, I am. Thank you so much.