Reputation: 437
I have two property files in yml
application-common.yml with below content
web-client:
max-connections: 500
wait-for:
time: 1s
application.yml with below content
info:
app:
name: "@project.name@"
version: "@project.version@"
spring:
application.name: "@project.name@"
---
spring:
config:
activate.on-profile: local
import: classpath:application-common.yml
wait-for:
time: 10s
---
spring:
config:
activate.on-profile: prod
import: classpath:application-common.yml
wait-for:
time: 5s
I was expecting that I should be able to override wait-for
property after importing application-common.yml
to 10s
for the local
profile and 5s
for the prod
profile. But when I run the application with local
profile, the wait-for
property is resolved to 1s
instead of 10s
Upvotes: 3
Views: 2060
Reputation: 119
You can override the property by redefining it in another yml or properties file. But make sure that, which ever property file gets read at last, those properties will be effective/considered in the application.
e.g. if your common yml file gets read last, then "wait-for" will be 1s & if application yml file gets read last, then "wait-for" will be 10s.
Upvotes: 1
Reputation: 5321
I'm not very sure about this response since I haven't testet it, but I think the standard layout should rather be as follows:
application.yml
<= shared/common stuffapplication-local.yml
<= local
profile specific overridesapplication-prod.yml
<= prod
profile specific overridesAt least, that's how I would intuitively do it to follow best practices and would expect it to work.
Upvotes: 2