Reputation: 2943
Spring boot version: 2.5.0
I've different property files. 3 inside the jar and one on the server (for overriding the properties with server specific)
The active profile and external properties' path is configured in the application.properties.
spring.profiles.active=@prodProfile@
spring.config.import=optional:file:./application-local.properties
Where the values of @prodProfile@ is coming from the profile configuration part of pom.xml.
<properties>
<prodProfile>prod</prodProfile>
</properties>
If I have same properties in application-prod.properties and application-local.properties, which has precedence? When I tested, I've found that profile specific has precedence. Not able to override the property value with spring.config.import. Is it expected behavior?
Upvotes: 6
Views: 6498
Reputation: 116061
Yes, this is the expected behaviour. As described in the documentation, files imported using spring.config.import
are "treated as additional documents inserted immediately below the one that declares the import".
In your case, you are importing the file into application.properties
so it will be treated as general, non-profile-specific configuration. As such, profile-specific properties will take precedence.
Upvotes: 4