SpringBoot 多Profile使用與切換方式
Spring中Profile對不同環(huán)境提供不同配置功能的支持,可以通過激活、指定參數(shù)等方式快速切換環(huán)境。
文件名格式:application-{profile}.properties
可以建立多個(gè)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 (未指定時(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。通過設(shè)置active選擇不同配置文件:set JAVA_OPTS="-Dspring.profiles.active=test"
web.xml方式
spring.profiles.active prod
標(biāo)注方式(junit單元測試非常實(shí)用)
@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實(shí)現(xiàn)多環(huán)境支持
- springboot學(xué)習(xí)筆記之 profile多環(huán)境配置切換的實(shí)現(xiàn)方式
- 使用Spring boot 的profile功能實(shí)現(xiàn)多環(huán)境配置自動切換
- SpringBoot多Profile配置的實(shí)現(xiàn)示例
相關(guān)文章
SpringBoot實(shí)現(xiàn)簡單的日志鏈路追蹤
隨著分布式應(yīng)用的普及,現(xiàn)在的一些應(yīng)用系統(tǒng)不再像以前,所有的文件(前后端程序)都打包在一個(gè)包中,本文通過一個(gè)簡單的SpringBoot應(yīng)用來總結(jié),我們?nèi)绾螌⑷罩敬?lián)起來,文中有詳細(xì)的代碼示例,需要的朋友可以參考下2023-10-10關(guān)于springboot-starter-undertow和tomcat的區(qū)別說明
這篇文章主要介紹了關(guān)于springboot-starter-undertow和tomcat的區(qū)別說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03Spark SQL關(guān)于性能調(diào)優(yōu)選項(xiàng)詳解
這篇文章將為大家詳細(xì)講解有關(guān)Spark SQL性能調(diào)優(yōu)選項(xiàng),小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲2023-02-02通過實(shí)例解析Java類初始化和實(shí)例初始化
這篇文章主要介紹了通過實(shí)例解析Java類初始化和實(shí)例初始化,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11