pauldeason
Apr 4th, 2008, 09:09 AM
Hi,
I have a problem that Spring seems to be instantiating multiple instances of singletons. My web.xml config is as follows:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<description>Spring MVC Dispatcher Servlet</description>
<display-name>DispatcherServlet</display-name>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
It seems the ContextLoaderListener creates them first and then the DispatcherServlet also instantiates new versions of the same beans, even though they are all singletons.
If I remove the ContextLoaderListener then I only get one instance. However, for some legacy code I need to use the WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext); method which seems to require it.
I would have thought that the DispatcherServlet would just inherit the beans loaded by the listener. Does anybody know how to get round this, or alternatively access the WebApplicationContext without having the ContextLoadListener declared in the web.xml.
Any help greatly appreciated.
Thanks
I have a problem that Spring seems to be instantiating multiple instances of singletons. My web.xml config is as follows:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<description>Spring MVC Dispatcher Servlet</description>
<display-name>DispatcherServlet</display-name>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
It seems the ContextLoaderListener creates them first and then the DispatcherServlet also instantiates new versions of the same beans, even though they are all singletons.
If I remove the ContextLoaderListener then I only get one instance. However, for some legacy code I need to use the WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext); method which seems to require it.
I would have thought that the DispatcherServlet would just inherit the beans loaded by the listener. Does anybody know how to get round this, or alternatively access the WebApplicationContext without having the ContextLoadListener declared in the web.xml.
Any help greatly appreciated.
Thanks