The difference between bootstrap and application and application scenarios

Official website explanation

Spring Cloud is built on Spring Boot . There are two contexts in Spring Boot, one is bootstrap and the other is application. Bootstrap is the parent context of the application, which means that bootstrap loading takes precedence over application. Bootstrap is mainly used to load configuration information from additional resources and can also decrypt properties in local external configuration files. Both contexts share an environment, which is the source of external properties for any Spring application. Properties in bootstrap will be loaded first, and they cannot be overridden by the same local configuration by default.

The difference between the two

1. Differences in loading order

The bootstrap configuration file is loaded before the application configuration file, because bootstrap is loaded by the spring parent context, and application is loaded by the child context.

2. Priority difference

The configuration information loaded by bootstrap cannot be overwritten by the same configuration of the application. If two configuration files exist at the same time, bootstrap will take priority.

3. Differences in application scenarios
Common application scenarios of bootstrap

Configure some fixed properties that cannot be overridden. Used for some system-level parameter configurations. The local configuration file cannot override the remote configuration by default.

Some scenarios require encryption/decryption.

When you use the Spring Cloud Config configuration center, you need to add the configuration attribute connected to the configuration center in the boostrap configuration file to load the configuration information of the external configuration center.

common application scenarios

Commonly used for automated configuration of SpringBoot projects and for some application-level parameter configurations.

Above, in most cases there is no need to distinguish between the two situations. You only need to use application, and the effect is basically the same.

Guess you like

Origin blog.csdn.net/juanxiaseng0838/article/details/132011629