Setting Springboot profiles on intellij Idea 2022.* community edition

896 Views Asked by At

I have a springboot application recently migrated to spring boot 2.7.0. I am facing a problem on intellij. My application consists of application-dev.properties application-local.properties ...

Before migration I would edit the run configurations and add VM option and give the value -Dspring.profiles.active=local and spring would automatically select application-local properties. When I try the same with the new version it is no longer working. It always defaults to application.properties which holds production config.

while I was checking some threads on stackoverflow they suggested that we should segregate the application-{env}.properties based on env and have a default application.properties which contains property spring.profile.active=local; this works but I want to know if there is a better way to do this by setting up a env variable or vm option

enter image description here

2

There are 2 best solutions below

2
akuma8 On

IntelliJ offers a way to set the profile for spring boot app in the run configuration. See below "Active profiles". You can still add environment variable SPRING_PROFILES_ACTIVE=local setting profile

0
Phanee M On

In the newer version of Springboot (2.7.0+) The application.properties is selected by default regardless of what VM option is selected.

  • We should have environment specific application.properties. For example application-local.properties
  • Create an empty application.properties file.
  • With this setup spring will select the right application-{env}.properties file.

Note: You still need to have the VM argument in the run configurations -Dspring.profiles.active={env}