Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 375
sonoerin Avatar asked Feb 24 '17 20:02

sonoerin


People also ask

How do I change application properties in IntelliJ?

Create a properties fileRight-click a directory where you would like to create the file. From the context menu of the target directory, choose New | File. In the New File dialog, type the filename with the corresponding extension . properties, and click OK.

How do I pass properties file in IntelliJ?

In the list, select the module that you want to add one or more properties files to. On the right, select the Dependencies tab. Click the green plus and select "Jars or directories". Intellij will now ask you what the "category" of the selected file is.


1 Answers

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

like image 91
Jay Avatar answered Sep 19 '22 15:09

Jay