I would like to know the priority of the application-{profile}.properties
files, if multiple spring.profiles.active
are added.
For example:
spring.profiles.active=profile1,profile2
src/main/resources
, I have these files application-profile1.properties
and application-profile2.properties
I have read this and but it doesn't cover this topics here.
Thanks in advance.
In the application. properties we have set the local profile to be active. With the SpringApplicationBuilder's profiles method we add two additional profiles.
Spring profiles can also be activated via Maven profiles, by specifying the spring. profiles. active configuration property. This command will package the application for prod profile.
To see all properties in your Spring Boot application, enable the Actuator endpoint called env . This enables an HTTP endpoint which shows all the properties of your application's environment. You can do this by setting the property management.
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.
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:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With