How are contacty Spring mvc (DispatcherServlet/Context-param)?

No I think what is the relation between different settings of the spring context.
Here in the simplest version of all just
<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>

there are only a DispatcherServlet and sootvetsvenno Dispatcher-servlet.xml. If you wish, using init parameters you can rename it in servlet-context.xml. It's all clear.

But there, at the same web.xml add a block
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/spring-security.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>


And I can not understand what is the difference root-context.xml and the usual servlet-context.xml ?
Why have one if there's another ?
June 26th 19 at 14:11
1 answer
June 26th 19 at 14:13
Solution
This is done in order not to bring down all the settings in one pile. In large projects single file with all the settings can be huge. It will be a long time to find the desired setting, if you want to edit, and easy to get confused. Therefore, the basic configuration and the announcement of bins in a single file, the security settings in other, settings to access the data in the third configuration mvc in fourth and so on. As a result, the context will be one, but the settings for it will be taken from different files. But it is better than multiple files to transfer in param-value and in root-context.xml to connect other files with the import Directive.
Thank you ) - modesta_McLaughlin commented on June 26th 19 at 14:16
No, in the example above creates 2 context:
  1. Parent - raised with the help of ContextLoaderListener and files root-context.xml and spring-security.xml. This context is usually issued services, connection pooling, database, schedulers, etc.
  2. Child - For the MVC and is only available to the servlet DispatcherServlet. In the child context can see all of Bina from the parent + controller settings
- rogelio_Hintz76 commented on June 26th 19 at 14:19
: thank you. Like understood. - modesta_McLaughlin commented on June 26th 19 at 14:22

Find more questions by tags JavaSpring