i'm using system property define location environment-specific properties file. however, override value different integration tests.
here's production spring setup. i'm using custom propertyplaceholderconfigurer resolve encrypted property file values, that's not important here:
<-- spring configuration in file service-spring-beans.xml --> <bean class="com.mycompany.mypropertyplaceholderconfigurer"> <property name="locations"> <list> <value>classpath:properties/${my_environment}/${my_environment}.properties</value> </list> </property> <property name="ignoreresourcenotfound" value="false"/> <property name="ignoreunresolvableplaceholders" value="true"/> </bean> at runtime, define value of my_environment java system property. works expected. however, integration tests, define my_environment "inttest", integration-test specific property file properties/inttest/inttest.properties loaded.
i've tried use spring context loaded integration-test set string bean id my_environment:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="com.mycompany.myclasses"/> <bean class="java.lang.string" id="my_environment"> <constructor-arg value="inttest"/> </bean> <!-- imports production spring context --> <import resource="classpath:service-spring-beans.xml"/> </beans> however, value of my_environment not resolved , , error when running integration tests.
caused by: org.springframework.beans.factory.beaninitializationexception: not load properties; nested exception java.io.filenotfoundexception: class path resource [properties/${my_environment}/${my_environment}.properties] cannot opened because not exist
how can override my_environment @ inttest time without passing system property jvm?
since using maven surefire plugin run integration tests, simplest solution turned out setting system property using surefire plugin configuration, this:
<configuration> <systempropertyvariables> <my_environment>inttest</my_environment> </systempropertyvariables> <!-- ... --> <configuration>
Comments
Post a Comment