What is the difference between bootstrap and application in springboot?

The difference in loading order:

    bootstrap.yml (bootstrap.properties) is loaded first

    Load after application.yml (application.properties)

    bootstrap.yml is used in the bootstrap phase of the application context and is loaded by the parent Spring ApplicationContext. The parent ApplicationContext is loaded before using application.yml. 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 applicaton. Bootstrap is mainly used to load configuration information from additional resources, and can also decrypt properties in local external configuration files. These two contexts share an environment, which is the source of external properties of any Spring application. The properties in bootstrap will be loaded first, and they cannot be overridden by the same local configuration by default.

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

Application scenarios of bootstrap/ application:

    Both bootstrap.yml and application.yml can be used to configure parameters.

     The application configuration file is easy to understand, application.yml can be used to define the application level, mainly for the automatic configuration of Spring Boot projects.

     The bootstrap configuration file has the following application scenarios. When using the Spring Cloud Config configuration center, you need to add configuration attributes connected to the configuration center in the bootstrap configuration file to load the configuration information of the external configuration center; some fixed attributes that cannot be overridden and some encryption/decryption scenarios. Bootstrap.yml can be understood as some parameter configurations at the system level, and these parameters generally remain unchanged.

 

 

Guess you like

Origin blog.csdn.net/qq_36073688/article/details/113148929