If you are SpringApplication
SpringApplicationBuilder
building an application context from or, add the bootstrap context as the parent of the context. This is a spring feature where the child context inherits the property source and configuration file from its parent process, so the "main" application context will contain additional property sources compared to building the same context without using Spring Cloud CONFIG. Additional sources of property are:
"Bootstrap": if any is found in the bootstrap context PropertySourceLocators
, the optional CompositePropertySource
display is high priority and has a non-empty property. An example is the properties from the Spring Cloud config server. For instructions on how to customize the contents of this property source, see below.
"Applicationconfig:[classpath:bootstrap.yml]" (a friend if the spring profile is active). If you have one bootstrap.yml
(or property), these properties are used to configure the boot context and then add them to the child context when the parent process is set. They have a lower priority than application.yml
(or attributes) and any other property sources that are added to the child as a normal part of the process of creating a spring boot application. For instructions on how to customize the contents of these property sources, see below.
Because of the collation of the property source, the boot entry takes precedence, but note that these entries do not contain bootstrap.yml
any data from, and it has a very low priority, but can be used to set the default value.
You can extend the context hierarchy by simply setting any ApplicationContext
parent context you create, such as using your own interface, or using SpringApplicationBuilder
convenient methods ( parent()
, child()
and sibling()
). The boot environment will be the parent of the highest ancestor you create yourself. Each context in the hierarchy will have its own bootstrap property source (possibly empty) to avoid inadvertently escalating the value from the parent to its descendants. Each context in the hierarchy (in principle) can also be different spring.application.name
, so if there is a configuration server, a different remote property source. Normal Spring Application context behavior rules apply to attribute resolution: properties in a child environment override properties in the parent by name and property source name (such as the fruit level has the same property source as the parent name, and a child from the parent is not included in the child).
Note that SpringApplicationBuilder
you are allowed to share throughout the hierarchy Environment
, but this is not the default value. Thus, in particular, sibling situations do not need to have the same information or sources of property, although they share common ground with parents.
Springcloud Application Context Hierarchy