Define multi level spring application.yml hierarchy

Viewed 457

However, the most important profiles-related feature that Spring Boot brings is profile-specific properties files. These have to be named in the format application-{profile}.properties.
Spring Boot will automatically load the properties in an application.properties file for all profiles, and the ones in profile-specific .properties files only for the specified profile.

-- from https://www.baeldung.com/spring-profiles

So this is possible:

application.yml:

spring:
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

application-dev.yml:

spring:
  datasource:
    url: jdbc:sqlserver://development.server:14331;databaseName=Dev;

When you use the dev profile, Spring would load the 'driver-class-name' from application.yml


I am searching for something like this:

application-dev-myconfig.yml:

spring:
  datasource:
    username: myVeryOwnDbUser
    password: myVeryOwnPassword

Now if you use the dev-myconfig profile it should take the 'url' from dev profile and the 'driver-class-name' from the default profile.

Is it possible to have another level, like this? Or how would you do that?

Thanks and have a good Day :)

1 Answers

You can have more than one active spring profile and that would solve your problem. In your case -Dspring.profiles.active=dev,dev-myconfig

Related