htshame
htshame

Reputation: 7330

Multiple profiled properties configuration in Spring-boot 2

I have a spring-boot 2.1.3.RELEASE application with multiple properties files.

In my /src/main/resources I have my-app.properties and profiled my-app-local.properties.

Also, outside the project I have another profiled properties file /config/my-app-local.properties.

The point of this configuration is to have the following properties hierarchy:

  1. /resources/my-app.properties
  2. /resources/my-app-local.properties
  3. /config/my-app-local.properties

So when I try to run the application with the following parameters:

--spring.profiles.active=local --spring.config.name=my-app --spring.config.location=config/my-app.properties

the application fails to start because it can't find any properties files.

However, this configuration and parameters worked perfectly on spring-boot 1.5.19.RELEASE. How can the same be achieved in spring-boot 2?

Upvotes: 0

Views: 446

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 39978

use spring.config.additional-location doc

When custom config locations are configured by using spring.config.location, they replace the default locations. For example, if spring.config.location is configured with the value classpath:/custom-config/,file:./custom-config/, the search order becomes the following:

file:./custom-config/
classpath:custom-config/

Alternatively, when custom config locations are configured by using spring.config.additional-location, they are used in addition to the default locations. Additional locations are searched before the default locations. For example, if additional locations of classpath:/custom-config/,file:./custom-config/ are configured, the search order becomes the following:

file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/

Upvotes: 1

Related Questions