0

After generating a simple web app using Spring initializr, I created 2 YML files in src/main/resources folder:

  • application.yml
  • application-prod.yml

and added 2 different values inside each of them:

# application-prod.yml
app:
  name: demo-prod

#application.yml
app:
  name: demo-local

Then I built the app with mvn clean install -Dspring.profiles.active=prod -DskipTests. And started the app with mvn spring-boot:run -Dspring.profiles.active=prod.

Looking at the log lines of the startup, I can see that there was no active profile defined and Spring will fall back to the default one:

No active profile set, falling back to default profiles: default`

What am I missing, why Spring didn't see my profile prod passed in from the CLI?

belgoros
  • 3,590
  • 7
  • 38
  • 76
  • Does this answer your question? [how to use Spring Boot profiles](https://stackoverflow.com/questions/40060989/how-to-use-spring-boot-profiles) – eis Mar 30 '21 at 16:52
  • 1
    Also: [Setting active profile and config location from command line in spring boot](https://stackoverflow.com/questions/31038250/setting-active-profile-and-config-location-from-command-line-in-spring-boot) – eis Mar 30 '21 at 16:52
  • in short, in spring boot 2.0+ the parameter with maven is called `spring-boot.run.profiles` – eis Mar 30 '21 at 16:53
  • @eis: running as you suggested `mvn spring-boot:run -Dspring-boot.run.profiles.active=prod` had no effects. – belgoros Mar 30 '21 at 16:55
  • I did not suggest that? please re-read what I suggested :) (or see the links I provided) – eis Mar 30 '21 at 17:01
  • 2
    The following worked for me: `mvn spring-boot:run -Dspring-boot.run.profiles=prod` displaying clearly that the profile `prod` was active: `The following profiles are active: prod`. Thank you guys! – belgoros Mar 30 '21 at 17:03

0 Answers0