Spring Boot has an idea of how to build applications using Spring: for example, it has a general location for general configuration files and an endpoint for common administrative and monitoring tasks. Spring Cloud builds on this and adds some functionality that may be used or occasionally needed by all components in the system.

Boot Application Context A Spring Cloud application operates by creating a “boot” context, which is the parent context of the main application. Out of the box, responsible for loading configuration properties from external sources and decrypting properties in local external configuration files. The two contexts share an Environment, which is the source of external attributes for any Spring application. The Bootstrap attribute has a high priority and cannot be overridden by local configuration by default.

The boot context uses a different external configuration convention than the main application context, so use bootstrap.yml application.yml (or.properties) instead of the bootstrap.yml and main-on-context external configuration. Ex. :

bootstrap.yml spring: application: name: foo cloud: config: uri: The ${} SPRING_CONFIG_URI: http://localhost:8888 if your application requires application specific configuration of the server, It’s a good idea to set spring.application.name (in bootstrap.yml or application.yml).

You can set up spring. Cloud. The bootstrap. Enabled = false (for example) in the system properties to completely disable the boot process.

Application context hierarchy if you are building an application context from SpringApplication or SpringApplicationBuilder, add the Bootstrap context as the parent of that context. This is a Spring feature where a subcontext inherits property sources and configuration files from its parent process, so the “main” application context will contain other property sources compared to building the same context without Spring Cloud Config. Additional sources of property are:

“Bootstrap” : If any PropertySourceLocators are found in the bootstrap context, the optional CompositePropertySource is shown as high priority and has a non-empty property. One example is a property from the Spring Cloud Config server. See below for instructions on how to customize the content of this attribute source.

“ApplicationConfig: [CLASspath: bootstrap.yml]” (friend if the Spring configuration file is active). If you have a bootstrap.yml (or properties), these properties are used to configure the boot context and then added to the child context when the parent process is set up. They take precedence over application.yml (or properties) and any other source of properties added to a child as a normal part of the process of creating a Spring Boot application. See below for instructions on how to customize the content of these attribute sources.

Due to the collation of the property sources, the “boot” entries take precedence, but note that these entries do not contain any data from bootstrap.yml, which has a very low precedence but can be used to set defaults.

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 convenience methods (parent(), child() and sibling())). The boot environment will be the parent of your highest level ancestor that you created. Each context in the hierarchy will have its own “bootstrap” attribute source (which may be empty) to avoid unintentionally upgrading values from a parent to its descendants. Each context in the hierarchy can also (in principle) have a different Spring.application.name, so a different source of remote properties if a configuration server exists. The normal Spring application context behavior rules apply to attribute resolution: attributes in the child environment override attributes in the parent by name and attribute source name (if the child has the same attribute source as the parent, a child from a parent is not included in the child).

Note that SpringApplicationBuilder allows you to share the Environment throughout the hierarchy, but this is not the default. Thus, fraternal situations in particular do not require the same sources of information or property, even though they share common ground with parents.



Minglisoft. Cn/honghu/tech…