Configuring multiple Spring Context files
You can use either contextConfigLocation within the web.xml file or an import tag within the "parent" context file. Below are examples of each.
<context-param>
<param-name>contextConfigLocation
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/routerContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="/WEB-INF/routerContext.xml" />
.....
</beans>
Another item contextConfigLocation is useful for is referencing Spring context files of other components (see code below). By this I mean independent source code projects that are JAR-ed up and placed in the web apps lib directory. Independent source code projects allow teams to code, test and deploy subsystems independently from the main web application. Thanks to Matt Raible for posting this trick on Spring-live.
contextConfigLocation
\WEB-INF\applicationContext.xml,classpath:/routerContext.xml
Of course, your unit testing needs to also be aware of the new "component" and this can be accomplished simply by passing a String array to the FileSystemXmlApplicationContext constructor (see code below).
String[] contexts = new String[]{"C:\\dev\\data\\workspaces\\impulse\\gate\\Web Content\\WEB-INF\\applicationContext.xml",
"classpath:/routerContext.xml"};
appContext = new FileSystemXmlApplicationContext(contexts);

0 Comments:
Post a Comment
<< Home