The role of bootstrap.yml

bootstrap.yml is a configuration file for Spring Boot applications that is  application.yml loaded earlier than and serves two main purposes:

1. External configuration file before loading application context

When the SpringBoot application starts, it will first load the properties defined in the bootstrap.yml file. These properties can be used to configure services such as external configuration servers, encryption/decryption, configuration log levels, etc. that are required before the application context.

2. As the parent context of the application context

Configuring the resolver for Spring applications (Spring Application Context Hierarchies) Through bootstrap.ymlthe configuration in, you can use the application context of Spring Boot applications as parent contexts and separate them from other application contexts. The advantage of this is that beans in the parent context can be inherited and overridden in the child context, achieving configuration flexibility in different environments.

It should be noted that bootstrap.yml it is loaded at the earliest stage of application startup, so its configuration priority is higher than  application.yml other configuration files. Therefore, if  bootstrap.yml attributes with the same name are defined in and other configuration files, bootstrap.yml the attributes defined in will take precedence.

In addition, bootstrap.ymlfile naming can also be used bootstrap.properties. At this time, the configuration format is in the form of key-value pairs, not ymlformat.

Guess you like

Origin blog.csdn.net/Isonion/article/details/132806991