7

I would like to know the priority of the application-{profile}.properties files, if multiple spring.profiles.active are added.

For example:

  • Let say, I have this spring.profiles.active=profile1,profile2
  • And in my src/main/resources, I have these files application-profile1.properties and application-profile2.properties
  • If both of the files config the same property, but with different values, which one will be the one shown?

I have read this and but it doesn't cover this topics here.

Thanks in advance.

Ng Sek Long
  • 4,233
  • 2
  • 31
  • 38

3 Answers3

11

According to the documentation, the last profile specified wins.
In your example : spring.profiles.active=profile1,profile2, the properties of profile2 should overwrite the properties of profile1.

In the point 24.4 Profile-specific Properties of the documentation, you can read :

If several profiles are specified, a last-wins strategy applies. For example, profiles specified by the spring.profiles.active property are added after those configured through the SpringApplication API and therefore take precedence.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • Thanks for the documentation, I missed that part of the documentation. – Ng Sek Long Apr 26 '19 at 09:36
  • 1
    You are welcome. Some parts fairly related of the Spring Boot documentation are sometimes exploded in two distinct parts to make it "digester". I also took some minutes to find it again. – davidxxx Apr 26 '19 at 11:22
2

First Spring loads default profile (application.properties) and then it overrides it with your additional profiles in the same order you listed them. So in your case profile2 values will override everything you defined in profile and application.properties

The simplest way is to write very simple application and just check it:)

Planck Constant
  • 1,406
  • 1
  • 17
  • 19
  • 1
    Thanks, `The simplest way is to write very simple application and just check it` I am not familiar with Spring so writing that simple application will probably take me some time, I am actually doing that right now but still not yet finished. – Ng Sek Long Apr 26 '19 at 09:34
  • Your answer is very good, but a reference to the official document that I missed make the other answer the better answer, thanks! – Ng Sek Long Apr 26 '19 at 09:35
  • 1
    No problem. Good luck with your Spring application :) – Planck Constant Apr 26 '19 at 12:12
0

spring.profiles.active

Comma-separated list of active profiles. Can be overridden by a command line switch.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 20 '22 at 21:57