https://cloud.spring.io/spring-cloud-static/spring-cloud.html
-> Config Server
Bootstrap properties are added with high precedence, so they cannot be overridden by local configuration, by default.
application.yml -> main application context
bootstrap.yml -> locating external configuration
You can disable the bootstrap process completely by setting
spring.cloud.bootstrap.enabled=false
(e.g. in System properties).spring.cloud.config.enabled = false -> in child application?
Application Context Hierarchies
It is a feature of Spring that child contexts inherit property sources and profiles from their parent
bootstrap -> high priority from Bootstrap context -> properties from the Spring Cloud Config Server
applicationConfig [classpath:bootstrap.yml] -> configure the child context when its parent is set
-> have lower precedence than the application.yml
do not contain any data from
bootstrap.yml
, which has very low precedence, but can be used to set defaults.-> Also inside of config server
Child context can override properties in parent
properties from a child context override those in the parent, by name and also by property source name (if the child has a property source with the same name as the parent, the one from the parent is not included in the child)
Overriding the Values of Remote Properties
spring.cloud.config.allowOverride=true
Customizing the Bootstrap Property Sources
Adding additional beans to bootstrap context(via spring.factories) e.g. from different server/ db
@Configuration
public class CustomPropertySourceLocator implements PropertySourceLocator {
@Override
public PropertySource<?> locate(Environment environment) {
return new MapPropertySource("customProperty",
Collections.<String, Object>singletonMap("property.from.sample.custom.source", "worked as intended"));
}
}
No comments:
Post a Comment