I have the following maven profile configuration
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>spring.profiles.active</name>
<value>dev</value>
</property>
</activation>
</profile>
<profile>
<id>test</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>test</value>
</property>
</activation>
</profile>
</profiles>
I have this in application.properties
spring.profiles.active=dev
So dev
is my default for both spring and maven profiles.
I then have Windows system variable SPRING_PROFILES_ACTIVE
set with a value of test
to explicitly use the test profile.
which according to the documentation this should override the dev
value in my properties file
69.5 Set the active Spring profiles
The Spring Environment has an API for this, but normally you would set a System property (spring.profiles.active) or an OS environment variable (SPRING_PROFILES_ACTIVE). E.g. launch your application with a -D argument (remember to put it before the main class or jar archive):
$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
In Spring Boot you can also set the active profile in application.properties, e.g.
spring.profiles.active=production
A value set this way is replaced by the System property or environment variable setting, but not by the SpringApplicationBuilder.profiles() method. Thus the latter Java API can be used to augment the profiles without changing the defaults.
See Chapter 25, Profiles in the ‘Spring Boot features’ section for more information.
Now when I run my Spring application it IS using the test
profile in Spring, however the maven profile activation does not pick up on this and is still using the dev
profile.
I have tried setting SPRING_PROFILES_ACTIVE
as the name in the <property>
element to make sure it wasn't a issue with the lowercase .
version and the uppercase _
version but that didn't help.
It DOES work if I supply the variable when I run maven with -Dspring.profiles.active=test
.
Any help is greatly appreciated.
edit: apparently this also doesn't work when I deploy a war to tomcat where catalina.properties
contains spring.profiles.active=test
. The same thing, Spring uses test
but Maven is still stuck on dev
.