Spring: split the application context
Updated: 2009-03-06
There are many reasons to declare beans in more than one XML file. The most important reason is to maintain clear code with a logical separation of concerns. Additionally, as an application grows, a single file becomes insufficient for configuration.
Splitting applicationContext.xml in Spring
web.xml
To split the content of applicationContext.xml, declare contextConfigLocation in web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/yourApplicationServices.xml, /WEB-INF/yourApplicationDatabase.xml
</param-value>
</context-param>
You can also use Ant-style patterns to load multiple files, e.g., /WEB-INF/yourApplication*.xml.
For more details, refer to the Spring reference documentation.