Preferred approach to Switchyard multiple environment properties?
dustin.barlow Apr 7, 2014 3:45 PMI have been experimenting with using Maven profiles and filters to replace property values in the switchyard.xml file.
For example, I declare a property:
<sca:property value="${some.property}" name="someProperty"/>
I can then refer to it in any of my project's Bean classes by using:
@Property(name = "someProperty") private String someProperty;
Here is the build section of the pom.xml I'm using to do key=value substitution.
<build> <filters> <filter>src/main/filters/properties/${env}.properties</filter> </filters> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <debug>true</debug> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin> <plugin> <groupId>org.switchyard</groupId> <artifactId>switchyard-plugin</artifactId> <version>${switchyard.version}</version> <executions> <execution> <goals> <goal>configure</goal> </goals> </execution> </executions> <configuration> <scannerClassNames> <param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param> <param>org.switchyard.validate.config.model.ValidateSwitchYardScanner</param> </scannerClassNames> </configuration> </plugin> </plugins> </build>
When I run "mvn clean install -P dev", the ${env}.properties portion of the Maven filter file will be replaced with "dev.properties" (NOTE: for brevity I left out the <profile> section which sets the ${env} variable to "dev" based on the -P value passed in).
In the dev.properties file, I have a list of all the key=value pairs that I want to set during the build. Maven then recursively scans all the files in src/main/resources and substitutes any ${keys} with whatever values I have set in my src/main/filters/properties/dev.properties file.
The issue with this approach I've run into is that the Switchyard plugin kicks off AFTER the Maven filter logic and whatever replacement Maven did on the target version of switchyard.xml that gets bundled in the jar file is overwritten by the Switchyard build plugin and as a result all the key=value substitutions are lost.
If I comment out the Switchyard build plugin and run it again, then the resulting target switchyard.xml file has the correct key=values replaced. I assume that the Switchyard build is there for a reason (it was added by the Switchyard tooling) so commenting it out makes me a bit nervous as to what unknown side effects this may introduce.
So, what is the preferred way to do this type of multiple environment property management in Switchyard? I really like using the Maven profile filters approach because it's easy to do and I can manage everything in source control. However, I'm open to different solutions.