In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the Spring Boot designated external startup configuration file example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.
The default packaged spring boot project will type the configuration file into the jar package, and sometimes you need to modify some configuration items during testing. In addition to overwriting the configuration item with startup parameters, you can also specify an external configuration file to overwrite the existing configuration file. It is convenient when you need to modify more configuration parameters.
Use spring boot default profile path
The default search path is as follows:
1.file:./config/
2.file:./
3.classpath:/config/
4.classpath:/
It looks for loading application.yml or application.properties from 1-4 locations (this configuration file name can be modified by spring.config.name), for example,. / config/application.yml overwrites the configuration of the same name in. / application.yml and classpath:/config/applicaiton.yml.
That is, the easiest way is to place a configuration file in the same layer directory of the jar package, or under the configsubdirectory of the same layer directory, and start the jar package to load the configuration file to overwrite the configuration items.
Specify an external profile
Of course, you can specify the loading directory or file by changing the value of the startup parameter spring.config.location:
$java-jar myproject.jar-spring.config.location=classpath:/default.properties,classpath:/override.properties
Instead of going to the default location to load the configuration file, it loads the default.properties and override.properties files under the classpath, and the configuration with the same name in override.properties overrides default.properties.
If the specified path ends with /, it is a directory configuration and will go to the directory to find the configuration file. The default configuration of this parameter is:
Classpath:/,classpath:/config/,file:./,file:./config/
Compared with the default lookup path above, it is overridden from right to left.
Specific configuration
In the process of development, testing and release, these three scenarios are relatively fixed. Usually, three different configurations of application- {profile} .yml are defined and switched by the profile parameter when in use.
Applicaiton-dev.ymlapplicaiton-test.ymlapplicaiton-prd.yml
Switch the configuration file by specifying the spring.profiles.active parameter at startup
Java-jar myproject.jar-- spring.profiles.active=test
Of course, specifying a specific configuration also meets the rules for profile overwriting, but once the specified spring.config.location is not a directory, but a specific file, this parameter switch has no effect.
For more details on the extension configuration, please refer to the Externalized Configuration section of the official documentation of spring boot.
Thank you for reading this article carefully. I hope the article "sample Analysis of Spring Boot designated external Startup configuration File" shared by the editor will be helpful to you. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.