I want to control loading of a property file using Spring's property-placeholder and setting a system property. This works like it should:
<context:property-placeholder
location="classpath:jdbc/jdbc.${TARGET_ENV}.properties" />
When I run my application in different environment, I set system property TARGET_ENV and correct property file is picked up.
Now I have my integration tests, and I want to force configuration to load a specific property file (jdbc.INTEGRATION_TESTS.properties) always.
I have
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/META-INF/spring/set-system-property.xml",
"classpath:/META-INF/spring/applicationContext.xml"})
public class AbstractIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests {
and set-system-property.xml (using advice from Set System Property With Spring Configuration File):
<beans>
<bean id="systemPrereqs"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{@systemProperties}" />
<property name="targetMethod" value="putAll" />
<property name="arguments">
<util:properties>
<prop key="TARGET_ENV">INTEGRATION_TESTS</prop>
</util:properties>
</property>
</bean>
but the property is not picked up by Spring:
Caused by: java.io.FileNotFoundException: class path resource [jdbc/jdbc.${TARGET_ENV}.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
Why does this not work? Is there something about bean instantiation, factory beans etc, that I am not getting?