springboot使用profile指定不同配置(尚硅谷)


 

 

 

 

 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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM