SpringBoot 多Profile使用與切換方式
Spring中Profile對(duì)不同環(huán)境提供不同配置功能的支持,可以通過(guò)激活、指定參數(shù)等方式快速切換環(huán)境。
文件名格式:application-{profile}.properties可以建立多個(gè)properties(yaml)文件來(lái)不斷的切換
application-dev.properties
server.port=8082
application-prod.properties
server.port=8083
application.properties
server.port=8081spring.profiles.active=dev
文件名格式:application-{profile}.yaml
server: port: 8082spring: profiles: active: dev---spring: profiles: devserver: port: 8083---spring: profiles: prodserver: port: 8084---spring: profiles: default (未指定時(shí)默認(rèn)使用的配置)server: port: 80激活方式:
yaml中:spring: profiles: active: dev 或properties中:spring.profiles.active=dev運(yùn)行時(shí):
在打包后運(yùn)行的時(shí)候,添加參數(shù):
java -jar spring-boot.jar --spring.profiles.active=dev;
tomcat 中 catalina.bat(.sh中不用“set”) 添加JAVA_OPS。通過(guò)設(shè)置active選擇不同配置文件:set JAVA_OPTS='-Dspring.profiles.active=test'
web.xml方式
spring.profiles.active prod標(biāo)注方式(junit單元測(cè)試非常實(shí)用)@ActiveProfiles({“dev”})
到此這篇關(guān)于SpringBoot 多Profile使用與切換方式的文章就介紹到這了,更多相關(guān)SpringBoot 多Profile使用與切換內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
