SpringBoot 多Profile使用與切換方式
Spring中Profile對不同環(huán)境提供不同配置功能的支持,可以通過激活、指定參數(shù)等方式快速切換環(huán)境。
文件名格式:application-{profile}.properties
可以建立多個properties(yaml)文件來不斷的切換
application-dev.properties
server.port=8082
application-prod.properties
server.port=8083
application.properties
server.port=8081 spring.profiles.active=dev
文件名格式:application-{profile}.yaml
server: port: 8082 spring: profiles: active: dev --- spring: profiles: dev server: port: 8083 --- spring: profiles: prod server: port: 8084 --- spring: profiles: default (未指定時默認(rèn)使用的配置) server: port: 80
激活方式:
yaml中: spring: profiles: active: dev 或 properties中: spring.profiles.active=dev
運行時:
在打包后運行的時候,添加參數(shù):
java -jar spring-boot.jar --spring.profiles.active=dev;
tomcat 中 catalina.bat(.sh中不用“set”) 添加JAVA_OPS。通過設(shè)置active選擇不同配置文件:set JAVA_OPTS="-Dspring.profiles.active=test"
web.xml方式
spring.profiles.active prod
標(biāo)注方式(junit單元測試非常實用)
@ActiveProfiles({“dev”})
到此這篇關(guān)于SpringBoot 多Profile使用與切換方式的文章就介紹到這了,更多相關(guān)SpringBoot 多Profile使用與切換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot中的Profile多環(huán)境配置方法
- SpringBoot中多環(huán)境配置和@Profile注解示例詳解
- SpringBoot?Profile多環(huán)境配置方式
- SpringBoot?Profiles?多環(huán)境配置及切換
- SpringBoot配置Profile實現(xiàn)多環(huán)境支持
- springboot學(xué)習(xí)筆記之 profile多環(huán)境配置切換的實現(xiàn)方式
- 使用Spring boot 的profile功能實現(xiàn)多環(huán)境配置自動切換
- SpringBoot多Profile配置的實現(xiàn)示例
相關(guān)文章
關(guān)于springboot-starter-undertow和tomcat的區(qū)別說明
這篇文章主要介紹了關(guān)于springboot-starter-undertow和tomcat的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03Spark SQL關(guān)于性能調(diào)優(yōu)選項詳解
這篇文章將為大家詳細(xì)講解有關(guān)Spark SQL性能調(diào)優(yōu)選項,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲2023-02-02