“This is the fifth day of my participation in the August More Text Challenge.
There is a lot of automation in SpringBoot, but it is inevitable that you will need to configure some things yourself. The theory does not follow the practical requirements, and these configurations need to be customized. The custom configuration file is the application.properties file in the Resource directory, of course Use the YAML configuration instead.
The application.properties file can appear in one of four locations in a Springboot project. Respectively is:
- Config folder in the project root directory
- Project root directory
- The config folder in classpath
- The classpath directory
The picture above illustrates the situation:
The red numbers in the figure represent the priority of Springboot project loading configuration robustness. One digit is the first, and four digits are the last. Springboot will load the found configuration information into the SpringEnvironment according to this priority. Of course, if you use a yamL configuration file instead of a Properties configuration file,Springboot loads it in the same order, from config-> project -> config-> classpath. By default,Springboot queries and loads them in the same order as shown above. If you feel application.properties is too long, you can customize the name. For example, to create a configuration file named app in the classpath, you can package it as a jar, using the following command:
Jar — spring.config. name=app
You can also use the following command to specify the directory where the configuration file resides, ending with a slash
Name =app –spring.config.location=classpath:/
OK, that’s it for now. I used to know that configuration files are in the classpath, but now I know that there are four places to put them. The level is limited, if you have any questions, please point out, thank you.