Springcloud Application Context Hierarchy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.