Rather than messing with a context's parents, I decided to leave it up to Ant to create the different company-servlet.xml files based on a master config file.
Here's the ant script:
Code:
<target name="springConfig" depends="init">
<copy tofile="${webapp}/WEB-INF/company1-servlet.xml" file="${web}/WEB-INF/master-servlet.xml" overwrite="true" />
<replace file="${webapp}/WEB-INF/company1-servlet.xml">
<replacetoken>${servlet-name}</replacetoken>
<replacevalue>company1</replacevalue>
</replace>
<copy tofile="${webapp}/WEB-INF/company2-servlet.xml" file="${web}/WEB-INF/master-servlet.xml" overwrite="true" />
<replace file="${webapp}/WEB-INF/company2-servlet.xml">
<replacetoken>${servlet-name}</replacetoken>
<replacevalue>company2</replacevalue>
</replace>
</target>
and master-servlet contains:
Code:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>/WEB-INF/jdbc-${servlet-name}.properties</value></property>
</bean>
This allows me to keep a single Spring configuration file at source. However, it also means all of my database & transactional configuration (basically everything) is in the servlet config file instead of the the parent applicationContext.xml file. In fact, I'm thinking of doing away with the applicationContext.xml file completely on the webapp, that way I can use the single config file for JUnit tests using a similar ant task to the one shown above.
Does this seem a valid approach?
Also, if this single config file begins to get unwieldy, is there a simple way of chaining Spring config files together declaratively?