problem
In a large project structure, the Spring ' s bean configuration files is located at different folders for easy Maintainabil ity and modular. For Example,spring-common.xml in Common folder, Spring-connection.xml in Connection folder,spring-modulea.xml in Modulea Folder...and etc.
You could load multiple Spring bean configuration files in code:
ApplicationContext context =
new Classpathxmlapplicationcontext (new string[] {"Spring-common.xml",
" Spring-connection.xml "," Spring-modulea.xml "});
Or put all spring XML files under Project Classpath.
Project-classpath/spring-common.xml
project-classpath/spring-connection.xml
project-classpath/ Spring-modulea.xml
Solution
The above ways is lack of organize and error prone, the better of the should is organize all your Spring bean configuration Files into a single XML file. For example, create Aspring-all-module.xml file, and import the entire Spring bean files like this:
File:spring-all-module.xml
<beans xmlns= "Http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
xsi:schemalocation=" Http://www.springframework.org/schema/beans/
http Www.springframework.org/schema/beans/spring-beans-2.5.xsd ">
<import resource=" common/ Spring-common.xml "/>
<import resource=" Connection/spring-connection.xml "/> <import resource=
"Modulea/spring-modulea.xml"/>
</beans>
Now, can load a single XML file like this:
ApplicationContext context =
new Classpathxmlapplicationcontext (Spring-all-module.xml);
Or put this file under Project Classpath.
Project-classpath/spring-all-module.xml
Note
In Spring3, the alternative solution is using Javaconfig @Import.