springboot掃描配置文件優先級分別是(高優先級覆蓋低優先級,不同內容的配置形成互補的配置):
file:./config/ file:./ classpath:/config/ classpath:/
手動指定配置文件路徑:
java -jar xxx.jar --spring.config.location=g:/application.properties
使用場景:項目已經打包了,修改了配置文件,無需再次打包,命令行重新指定修改后的配置文件路徑
用法1:配置文件內激活
主配置文件application.properties(使用application-dev.properties)
debug=true spring.profiles.active=dev
application.yml配置方法:
server:
profiles: dev
開發環境配置文件 application-dev.properties
server.port=8081
生產環境配置文件application-product.properties
debug=false
server.port=80
用法2:命令行
1、命令行參數
java -jar xxx.jar --sring.profies.active=dev
2、JVM參數
java -jar -Dspring.profiles.active=dev xxx.jar