目錄
通常只需要將application.yml放在和打包好的jar包同目錄即可。
當需要對多個jar包進行配置就不一樣了,需要將同級的application.yml文件改為aplication-all.yml(橫線后面的自定義,但是格式要對)
jar包中的配置文件保持原來名字
- jar包的application.yml中的代碼為
spring:
profiles:
active: all #表示指定后綴有-all的配置文件
src:
upload: ${src.upload} #引用指定配置文件中的值
product: ${src.procut}
frame: ${src.frame}
cutting: ${src.cutting}
indexmakerPath: ${src.indexmakerPath}
- 外部的application-all.yml代碼為
src:
uploadPath: D:\ProjectFiles\UploadFile\
productPath: D:\ProjectFiles\productFile\
framePath: D:\ProjectFiles\frame\
cuttingPath: D:\ProjectFiles\cutting\
ffmpegPath: D:\devsoft\ffmpeg\bin\
tmpFilePath: D:\ProjectFiles\UploadFile
tmpFilePath2: /ProjectFiles/UploadFile
zjx-upload-href: http://192.168.6.175:80/content/
indexmakerPath: D:\devsoft\rtspgw_0_13_2d_win32\
uploadproxypath: http://192.168.6.174:8889/ProjectFiles/UploadFile/
logconf: D:\IdeaProjects\toolupload\log\confFile\
frameproxy: http://192.168.6.174:8889/ProjectFiles/frame/
這樣其他的springboot就可以調用外部的配置文件了
在啟動jar的bat文件中也可以加上,來指定外部配置文件
--spring.profiles.active=api -Dspring.config.location=application-api.yml
一些優秀鏈接
主要描述了讀取外部配置文件的優先級關系springBoot項目打jar包后,修改配置文件中的配置項