springboot打包好的Jar檔案執行時引用外部的配置檔案
阿新 • • 發佈:2018-12-16
去Interview時被問了這個問題,之前都是直接在idea裡改好再打包了,所以沒有直接引用外部檔案過,通過檢視SpringBoot官網,得知有下面的幾種方法:
24.3 Application Property Files
SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:1、A /config subdirectory of the current directory // 大概意思是:放在jar包同級目錄下的子目錄config
2、The current directory //大概意思是:放在jar包目錄同級
3、A classpath /config package // 大概意思是在classpath下的config目錄
4、The classpath root // classpath中引用的優先順序和上面的順序是一樣的。
還有一種是用命令列
java -jar bootdemo-0.0.1-SNAPSHOT.jar --spring.config.location=./test.properties //此時test.properties和jar是同級目錄
我就只用第1種方便:
ok,筆記完畢。