-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Michael Welles opened SPR-1740 and commented
We just spent quite some time an issue that was due to a misconfiguration on our part. I
We did not understand that a DispatchServlet would inherit beans instantiated in the root web application context. We were under the impression, from section 13.2 that the dispatch servlet had it's own distinct WebApplicationContext, and thus had our dispatch servlet pointing to the same context.xml as our ContextLoaderListener ( in order, we thought, to prevent maintenence of two identical files). Doing so we were firing up two copies of all of our singletons.
Our fault for not grokking the docs properly, but all the same we were still under the impression that a DispatcherServlet created it's own distinct application context -- it was not clear to us that there was a hierarchy that could be relied on. We saw that it was scoped, but didn't understand how the heirarchy was defined or how to define it.
Maybe in the next release of the docs, this paragraph in 13.2 of the docs could be modified to read a bit more clearly? (suggestion follows)
Old:
In the example above, all requests ending with .form will be handled by the DispatcherServlet. The DispatcherServlet now needs to be configured. As illustrated in Section 3.11, "Introduction to the ApplicationContext", ApplicationContexts in Spring can be scoped. In the web MVC framework, each DispatcherServlet has its own WebApplicationContext, which contains the DispatcherServlet configuration beans. The default BeanFactory used by the DispatcherServlet is the XmlBeanFactory and the DispatcherServlet will on initialization look for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application. The default values used by the DispatcherServlet can be modified by using the servlet initialization parameters (see below for more information).
New:
In the example above, all requests ending with .form will be handled by the DispatcherServlet.
The DispatcherServlet now needs to be configured. As illustrated in Section 3.11, "Introduction to the ApplicationContext", ApplicationContexts in Spring can be scoped. In the web MVC framework, each DispatcherServlet has its own WebApplicationContext, which will inherit all the beans already defined in in the Root WebApplicationContext.
These inhereted beans defined can be overridden in the servlet specific scope, and new scope specific beans defined local to a given servlet instance. The framework will, on initialization of a Dispatcher, look for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and create the beans defined there, overriding the values of any that are already defined by the same name in the global scope.
What name it uses, and what it uses to parse the file can be modified by using servlet initialization parameters (see below for a full listing).
Affects: 1.2.6