spring-boot: -Dspring.profiles.active ignored when mvn spring-boot:run
Upgrading 1.0.2.RELEASE->1.1.0.RELEASE changed how passing profile to mvn spring-boot:run
works, the -Dspring.profiles.active
flag seems to be ignored. I created a simple project that reproduces the problem: https://github.com/kryger/bug-spring-maven-profiles
(Note that application.yml
defines port=3333, application-production.yml
defines port=1111)
Steps to reproduce:
- Check out the project - it uses 1.1.0.RELEASE
mvn spring-boot:run -Dspring.profiles.active=production
-> Tomcat starts on port 3333 (expected 1111)- Edit pom.xml and change
<version>
to1.0.2.RELEASE
mvn spring-boot:run -Dspring.profiles.active=production
again -> Tomcat starts on port 1111
I had a look at 1.1.0.RELEASE’s release notes but couldn’t find anything that would explain this change - no idea if it’s a bug or a feature 😃.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 33 (16 by maintainers)
Links to this issue
Commits related to this issue
- Method of activating profile has changed See https://github.com/spring-projects/spring-boot/issues/1095 — committed to dirkaholic/spring-boot-rest-example by dirkaholic 7 years ago
- Method of activating profile has changed See https://github.com/spring-projects/spring-boot/issues/1095 — committed to udinnet/micro-services by udinnet 7 years ago
- Method of activating profile has changed See https://github.com/spring-projects/spring-boot/issues/1095 — committed to udinnet/micro-services by udinnet 7 years ago
- KSR-127 Change the way to define env. Switch from spring.profiles.active to spring-boot.run.profiles See https://github.com/spring-projects/spring-boot/issues/1095#issuecomment-369324316 — committed to finnishtransportagency/ksr by n0ps 6 years ago
- KSR-127 Change the way to define env Switch from spring.profiles.active to spring-boot.run.profiles See https://github.com/spring-projects/spring-boot/issues/1095#issuecomment-369324316 — committed to finnishtransportagency/ksr by n0ps 6 years ago
(For reference) The command should be:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
I have always liked “SPRING_PROFILES_ACTIVE=production mvn spring-boot:run”. It’s the way to pass lots of critical env variables to really any app, maven or whatever.
I tried on spring boot 2. Two ways work
My mistake, it should be
-Dspring-boot.run.profiles
in 2.0. See https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/examples/run-profiles.html for details.It works using:
mvn spring-boot:run -Drun.profiles=default, primary, secondary
Please refer to: http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html
For Spring Boot 2 under PowerShell, this only worked surrounding dots within quotes, for example
mvn spring-boot:run "-Dspring-boot.run.profiles=default,local,h2,local-h2"
Without these quotes, maven complains about unknown lifecycle phases. And yes,mvn spring-boot:run -Dspring-boot".run."profiles=default,local,h2,local-h2
works just the same but it’s kinda counter-intuitive.Sorry for misunderstanding, my fault! It was about another thing but this one works:
This worked:
mvn spring-boot:run -Dspring-boot.run.profiles=hom
This worked
This is also covered in the migration guide on the wiki
It does set
spring.profiles.active
as a command-line argument (--spring.profiles.active
). The javadoc is correct as it states “argument”. It doesn’t state system property there at all.