Without any processing, Spring Boot will use application.properties or application.yml in the project by default to read the required configuration of the project.
I only record a few of the things I use here.
Access command line properties
By default, SpringApplication converts any command line option parameters (starting with - --server.port=9000) to property and adds them to the Spring environment.
For example, specify the port when starting a project:
java -jar analysis-speech-tool-0.0.1-SNAPSHOT.jar --server.port=9000
Spring Boot uses a very special PropertySource command, the purpose is to make the rewrite of property values in a certain order, and 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 your Spring environment, you can use the following code to disable them.
SpringApplication.setAddCommandLineProperties(false);
Application Properties File
SpringApplication will load properties from the file at the following location of application.properties and add them to Spring's environment:
The list is arranged in order of priority (properties defined at higher positions in the list will override attributes defined at lower positions).
If you don't like application.properties as the configuration file name, you can switch to another name by specifying the spring.config.name environment property. You can also refer to explicit locations using the spring.config.location environment attribute (comma-separated list of directory locations or file paths).
for example:
java -jar myproject.jar --spring.config.name = myprojectjava -jar myproject.jar --spring.config.location = classpath:/default.properties,classpath:/override.propertiesjava -jar -Dspring.config.location=D:/speech/default.properties analysis-speech-tool-0.0.1-SNAPSHOT.jar
Summarize
The above is the external optimization configuration method of Spring Boot configuration file after jar package introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!