Home  >  Article  >  Java  >  What is the difference between bootstrap and application in SpringBoot?

What is the difference between bootstrap and application in SpringBoot?

WBOY
WBOYforward
2023-05-16 17:46:342998browse

    Explanation of the difference between bootstrap and application

    Botstrap and application are configuration files in the SpringBoot project. Their differences mainly include the following aspects

    (1) Loading order difference

    The bootstrap configuration file is loaded prior to 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 application. If two configuration files exist at the same time, bootstrap will be the main one

    (3) Application Scenario differences Bootstrap common application scenarios

    1. Configure some fixed properties that cannot be overridden. Used for some system-level parameter configuration

    The local configuration file cannot overwrite the remote configuration by default. ’s

    2. Some scenarios that require encryption/decryption

    3. When you use the Spring Cloud Config configuration center, you need to add the configuration connected to the configuration center in the boostrap configuration file. Properties to load the configuration information of the external configuration center, the professional translation is as follows

    What is the difference between bootstrap and application in SpringBoot?

    application common application scenarios

    1. Commonly used in SpringBoot projects Automated configuration

    2. Used for some application-level parameter configuration

    In most cases, there is no need to distinguish between the two situations, just use application, and the effect is basically the same

    SpringBoot configuration priority (bootstrap and application)

    The difference between bootstrap and application

    • bootstrap.yml precedes application.yml.

    • In the ApplicationContext boot phase, bootstrap.yml can be used. Spring application context is loaded by the parent context ApplicationContext. Defines system-level parameter configurations. These parameters generally do not change.

    • application.yml is used to define application-level parameter configuration. When used with spring-cloud-config, parameters defined in application.yml can be dynamically replaced.

    • application.yml will override the parameter configuration of bootstrap.yml.

    springboot configuration priority

    From the inside to the outside, the outer layer covers the inner layer.

    Command line parameters> Operating system environment variables> Configuration files outside the application> Configuration files within the application

    After joining the springcloud configuration center

    Configuration center> Command line parameters> local application.yml > local bootstrap.yml

    Configuration allows override:

    spring:
      cloud:
        config:
          allowOverride: true
          overrideNone: true
          overrideSystemProperties: false

    The above is the detailed content of What is the difference between bootstrap and application in SpringBoot?. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete