Spring Boot has a view of how to build an application using spring: For example, it has a general location for regular profiles, and endpoints for common management and monitoring tasks. Spring Cloud builds on this and adds features that may be used or occasionally required by all components in the system.
Bootstrap Application Context
A spring cloud application operates by creating a "bootstrap" context that is the parent context of the main application. Out-of-the-box, responsible for loading configuration properties from external sources, and also decrypting properties in the local external configuration file. These two contexts share a environment, which is the source of any spring application's external properties. The Bootstrap property has a high priority, so it cannot be overwritten by the local configuration by default.
The boot context uses an external configuration convention that differs from the main application context, so use bootstrap.yml application.yml (or. properties) instead of the external configuration of the bootstrap and main context. Cases:
Bootstrap.yml
spring: application: name: foo cloud: config: uri: ${SPRING_CONFIG_URI:http://localhost:8888}
If your application requires application-specific configuration on the server, it is a good idea to set up spring.application.name (in Bootstrap.yml or application.yml).
You can completely disable the boot process by setting Spring.cloud.bootstrap.enabled=false (for example, in System Properties).
Application Context Hierarchy
If you build the application context from Springapplication or springapplicationbuilder, 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 propertysourcelocators are found in the bootstrap context, the optional Compositepropertysource is displayed as 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 a 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. Their priority is lower than application.yml (or property) 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 any data from BOOTSTRAP.YML, which has a very low priority, but can be used to set the default value.
You can extend the context hierarchy by simply setting the parent context of any applicationcontext you create, such as using your own interface, or using the Springapplicationbuilder convenient method (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 have 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 allows you to share environment throughout the hierarchy, 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.
Application for Spring cloud-context Services