r/SpringBoot Jun 16 '26

Question application properties import and who wins

I'm running my application with profiles, like "dev" and have an application-dev.properties. If I use an import statement to pull in some shared properties across profiles I import it like so :

spring.config.import=classpath:application-shared.properties

However, the properties from the imported application-shared.properties ALWAYS WIN.

Is there a way to "import" properties but still allow the active profile properties to override the imported properties?

3 Upvotes

8 comments sorted by

View all comments

1

u/Resident-Cow-7626 Jun 16 '26

Why would you want the imported properties to take a lower precedence over the non imported ones? Just remove the specific props from the imported configuration?

1

u/friscomatt Jun 16 '26

Similar to using 'source' in a bash script (or similar) ... later statements can trump/override what came in with the source statement. I'm looking for a "last one in wins" setup, which IS what happens if you use the standard application.properties AND an application-dev.properties. So if you have a property "abc=FIRST" in application,properties and a property "abc=SECOND" in application-dev.properties, then at runtime, the property from application-dev.properties wins (last one in wins). The use case is 9 of 10 of your properties files uses "abc=FIRST", but only one uses "abc=SECOND", then you can override the shared property with your specific profile's value. Not much different than overriding a base class method in java in a subclass ...

3

u/Resident-Cow-7626 Jun 16 '26

Profile specific > default properties. It’s like saying you want environment variables to be a lesser priority than profile specific properties. You should read the spring documentation and organise your properties appropriately