0 votes
in Spring by

Can we have multiple Spring configuration files?

1 Answer

0 votes
by

For Spring MVC applications, we can define multiple spring context configuration files through contextConfigLocation. This location string can consist of multiple locations separated by any number of commas and spaces. For example;

<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,/WEB-INF/spring/appServlet/servlet-jdbc.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

We can also define multiple root level spring configurations and load it through context-param. For example;

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/root-security.xml</param-value>

</context-param>

Another option is to use import element in the context configuration file to import other configurations, for example:

<beans:import resource="spring-jdbc.xml"/>

Related questions

0 votes
asked Apr 4, 2021 in Spring by Robindeniel
0 votes
asked Apr 4, 2021 in Spring by Robindeniel
...