引用官方的文档说明:
If you don’t like application.properties as
the configuration file name you can switch to another by specifying a spring.config.name environment
property. You can also refer to an explicit location using the spring.config.location environment
property (comma-separated list of directory locations, or file paths).
$ java -jar myproject.jar --spring.config.name=myproject
or
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
![]() |
|
|
If spring.config.location contains
directories (as opposed to files) they should end in / (and
will be appended with the names generated from spring.config.name before
being loaded, including profile-specific file names). Files specified in spring.config.location are
used as-is, with no support for profile-specific variants, and will be overridden by any profile-specific properties.
The default search path classpath:,classpath:/config,file:,file:config/ is
always used, irrespective of the value of spring.config.location.
This search path is ordered from lowest to highest precedence (file:config/ wins).
If you do specify your own locations, they take precedence over all of the default locations and use the same lowest to highest precedence ordering. In that way you can set up default values for your application in application.properties (or
whatever other basename you choose with spring.config.name)
and override it at runtime with a different file, keeping the defaults.
#!/bin/sh
#kill java pid
pidlist=`ps -ef|grep java|grep "trade"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
echo "no java application pid alive!"
else
echo "java application pid list :$pidlist"
kill -9 $pidlist
echo "kill java $pidlist:"
echo "service stop success"
fi
echo "service start ..."
#find ./ -name "*.jar" | xargs sh trade.sh
jarpackage=`find ./ -name "*.jar"`
echo " jar package name: $jarpackage"
nohup java -jar $jarpackage --spring.config.location=/var/www/config/application.properties > /data/logs/tomcat/trade-web.log 2>&1 & tail -f /data/logs/tomcat/trade-web.log
本文介绍了Spring Boot如何实现配置分离,通过设置环境变量可以改变默认的配置文件名,或者指定配置文件的位置。当目录包含子目录时,需要以`application`结尾,系统会自动加载包括特定环境的配置文件。同时,`spring.config.additional-location`指定的文件路径会覆盖默认值,允许设定默认配置并按需运行时覆盖。
![[Warning]](https://i-blog.csdnimg.cn/blog_migrate/a36c957216ffcac7942d7a9261e1935f.png)
909





