I’m having some problems with maven 3 and getting to load the right .properties file.
What I want to achieve is the following: With mvn -Plocal i want to load the setting-local.properties, and if its run with prod i want to load the settings-prod.properties.
It works by using mvn -Denv=local, but when I try with the -Plocal the variable are not loaded (settings-${env}.properties does not exist).
My pom.xml:
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>local</env>
</properties>
</profile>
</profiles>
In my applicationcontext I have want to load the env-variable:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:settings-${env}.properties
</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders">
<value>true</value>
</property>
</bean>
So whats the problem, should’nt it work both ways?
I think you are confusing Spring’s PropertyPlaceholderConfigurer with Maven’s Filtering mechanism. These are similar but completely separate mechanisms (but they can be used together).
Spring’s PropertyPlaceholderConfigurer allows you to acquire values from a properties file for use inside your Spring application context.
Maven’s filtering allows you to replace values in text files (including properties files) with values from your Maven properties and environment.
You can combine them but then it becomes a two stage process. Your Maven build uses filtering to put values in your properties files and then in turn this can be read by Spring. Confused? (I am)