External optimized configuration method of configuration file after spring boot jar package

Without any processing, spring boot will use the application. In the project by default Properties or application YML to read the required configuration of the project.

I only record a few things I use here.

Access command line properties

By default, spring application will convert any command line option parameters (starting with - -- server. Port = 9000) to property and add them to the spring environment.

For example, specify the port when starting the project:

Spring boot uses a very special propertysource command to rewrite property values in a certain order. In this order, command-line properties always take precedence over other property sources.

Of course, if you don't want to add command-line properties to the spring environment, you can disable them using the following code.

Application properties file

Spring application will start from application Properties load the properties from the file in the following location and add them to the spring environment:

The list is arranged in order of priority (the attributes defined in the higher position in the list will override the attributes defined in the lower position).

If you don't like application Properties as the configuration file name, you can specify spring config. Name environment attribute to switch to another name. You can also use spring config. The location environment property (comma separated list of directory locations or file paths) references explicit locations. For example:

summary

The above is the external optimization configuration method of spring boot configuration file after jar package introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>