【发布时间】:2012-12-21 21:51:06
【问题描述】:
web.xml 片段:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-security.xml</param-value>
</context-param>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
根据this answer:
2- DispatcherServlet 上下文成为根上下文的子级。 ...
我的问题是了解 Spring 如何做出此决定(将 DispatcherServlet 上下文附加到根上下文)。 appContext XML 文件中没有任何明确的内容来指定这一点,并且 AFAICT 没有任何内容可以在 XML 中指定来明确地建立这种关联。
当 DispatcherServlet 实例化其 appContext 时,它如何知道在其上调用 setParent()(SpringMVC 在没有根 appContext 的情况下也可以正常工作),如果已经存在多个非子 appContext,它将如何选择?
【问题讨论】:
标签: spring spring-mvc hierarchy applicationcontext