Spring-boot – IntelliJ IDEA not picking up correct application-{}.properties file

intellij-ideaspring-boot

I have a spring boot 1.5.1 project that uses profile properties file. In my /src/main/resources I have all my properties files
enter image description here

When using IntelliJ 2016.3.4 I set the

Run Configuration | Active Profile

to "local" and run it. I see this in the console:

The following profiles are active: local

But there is a value in the property file
data.count.users=2

and used as:

@Value("${data.count.users}")
private int userCount;

that is not being picked up and thus causing the error:

Caused by: java.lang.IllegalArgumentException: Could not resolve
placeholder 'data.count.users' in string value "${data.count.users}"

However, if I run this via gradle

bootRun {
  systemProperty 'spring.profiles.active', System.properties['spring.profiles.active'] }

as

gradle bootRun -Dspring.profiles.active=local

then everything starts up using the local profile as expected. Can anyone see why this is not being properly picked up? In IntelliJ Project Structure I have my /src/main/resources defined as my Resource Folders.

UPDATE:

Adding screenshot of Configuration:
enter image description here

Best Answer

I could be wrong here but it doesn't look like the spring.profiles.active environment variable is actually set in your configuration, regardless of what you've selected as your Active Profile. This may be a bug with IntelliJ.

However, setting the environment variable in Run -> Edit Configurations definitely works for me.

enter image description here

Related Topic