Loading of configuration files in SpringBoot

insert image description here

The springboot startup will scan the application.properties or application.yml file of the location as the default configuration file of springboot

file:./config/ (configuration file under the config folder in the project root directory)

file:./ (configuration file in the root directory of the project)

classpath:/config/ (configuration file under the config file in the resources directory)

classpath:/(configuration file in the resources directory)

According to the order of priority from high to low, the files in all locations will be loaded, and the high-priority configuration content will override the low-priority configuration content to form a complementary configuration

We can also change the default configuration by configuring spring.config.location

After the project is packaged, we can use the form of command line parameters to specify the new location of the configuration file when starting the project; the specified configuration file and the configuration files loaded by default work together to form a complementary configuration

1. maven -> package to package the project

2. Put the configuration file to be used in a local folder, such as: D:/application.properties

3. Command line execution command java -jar boot-config-position-xxx.jar – spring.config.location=D:/application.properties

In this way, even if the project is online, we can modify the local configuration file and use one line of commands, which greatly facilitates the operation and maintenance personnel.

Note:
properties configuration has a higher priority than yml. When a configuration item exists in both properties and yml, the value in properties will take effect and override yml. If a key only exists in a certain type of document, use the value directly.

Guess you like

Origin blog.csdn.net/u014365523/article/details/131919710