When does spring use application-dev.properties vs application.properties

Mikayil Abdullayev picture Mikayil Abdullayev · May 25, 2018 · Viewed 7.5k times · Source

I've got several Spring Boot applications. All of them are maven projects and in all of them, I have separate configuration files for different environments, like application.properties, application-dev.properties, application-uat.properties. When I run the application on from IDE it sometimes reads from application.properties file and sometimes from application-dev.properties file. I use IntelliJ IDEA for development and I haven't been able to figure out what determines which file to read from. Is it IDE dependent or is there some configuration in Spring that decides which properties file to pick?

Answer

Nikem picture Nikem · May 25, 2018

Most probably some of your Run configurations in Idea have configured Spring "profile" to run with. When you run Spring Boot application with, e.g., "dev" profile, then application-dev.properties file will be read in addition to application.properties. See here for more info