springboot reads external configuration files

I accidentally saw that the company’s project sringboot configuration file is placed in the jar package and level directory, and my own deployment of the springboot project is to directly use the configuration file in the jar package of the project, although I can open the jar to modify the configuration file or directly before packaging Change the configuration file and then package it, but when the development and deployment personnel are separated, it will be more troublesome.

So I explored the way of external configuration files

The priority of the way springboot reads the configuration file is as follows:

  1. Create a config folder in the same directory of the jar package, and then put the configuration file in this folder.
  2. Put the configuration file directly in the same level directory of the jar package.
  3. Create a config folder under the classpath, and then put the configuration file into it.
  4. Put the configuration file directly under the classpath.

Therefore, according to the read priority method of this configuration file, we can directly place the configuration file or build the conf folder under the jar package level directory, put the configuration file in , and execute the startup command normally to read the external configuration file

Guess you like

Origin blog.csdn.net/qq_44132240/article/details/113329484