web.xml fragment:
<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>
According to this answer:
2- The DispatcherServlet context becomes a child of the root context. ...
My question is to understand how Spring makes this decision (to attach the DispatcherServlet context to the root context). There's nothing explicit in either appContext XML file to specify this, and AFAICT there's nothing you can specify in the XML to make this association explicitly.
When the DispatcherServlet is instantiating its appContext, how does it know to call setParent()
on it (SpringMVC works just fine without a root appContext), and if there's more than one non-child appContext already in existence how would it choose?