Configuration method of springboot external configuration file

When we release springboot applications, they are usually packaged into jar packages, but our configuration files are packaged inside. It is more troublesome to modify the configuration files. If our environment needs to distinguish between development environment, test environment and generation environment, It is a very troublesome thing to modify the configuration file and pack it every time.

Next, teach you to use external configuration files or commands to modify configuration parameters.

(1) Modify the configuration parameters at the entrance of the external java command. If we use docker to run the jar package, we generally use this method:

java -jar -Dserver.port=8083 myapp.jar

 (2) Modify configuration parameters through external configuration files.

Create a config directory in the same level directory of your jar file, and then create an application.properties and application.yml file in the config directory. The priority of these two configuration files will be higher than the two configuration files in the jar package.

(3) Use spring cloud configuration center, such as nacos.

Guess you like

Origin blog.csdn.net/handsome0916/article/details/108054450