I want to use both ContextLoaderListener (so that I can pass Spring Beans to my servlet) as well as DispatchServlet (Spring MVC). However, currently I have to pass init param to these both class initializer:
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/app-config.xml
</param-value>
So, I use the same xml for these both classes. Wonder if it would lead to my beans being initialized twice? If yes, how would I do to avoid that?
For both
ContextLoaderListenerandDispatcherServlet, thecontextConfigLocationparameter is optional.ContextLoaderListenerdefaults to/WEB-INF/application.xml,DispatcherServletdefaults to/WEB-INF/servletname-servlet.xml.If you set these parameters explicitly, you should not set them to the same value. The
ContextLoaderListenerandDispatcherServletshould have contexts with different sets of bean definitions, since otherwise, as you say, the beans will be instantiated twice.