the ContextLoaderListener looks for applicationContext.xml (or for the file specified by the context-param contextConfigLocation. Again the path is relative to the context-root. I usually place mine in /WEB-INF/classes/applicationContext.xml, and set this as a value of the context-param).

 

 

The dispatcherServlet-servlet.xml is a child context to the one defined byapplicationContext.xml. The child context can access beans from the parent context, but the opposite is not true. So imagine you have a "web" context, with all controllers and web-related stuff, and a "main" context with everything else

 

It is advisable to have as few contexts as possible (for the sake of simplicity). But you can define multiple dispatcher servlets, and hence have multiple "child" contexts.

 

使用applicationContext.xml文件时是需要在web.xml中添加listener的:
<listener>
??? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
而这个一般是采用非spring mvc架构,如使用struts之类而又想引入spring才添加的,这个是用来加载Application Context。
如果直接采用SpringMVC,只需要把所有相关配置放到xxx-servlet.xml中就OK了。

applicationContext容器包含dispatcherServlet容器,当同时在这两个配置文件中配置<context:component-scan 标签进行扫描bean时,如果bean作用域配置为单例,那么分别在这两个容器中会生成两个不同的单例对象。