国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

spring profile多配置文件的切換

2019-11-09 19:26:37
字體:
來源:轉載
供稿:網友

老生常談的問題 開發環境 測試環境 生產環境分別對應的PRoperties配置文件

在最少改動代碼的基礎上進行靈活的切換

三個配置文件分別為 local.properties,test.properties,production.properties

1.在spring的配置文件里加上代碼

<!-- 測試環境配置文件 -->    <beans profile="test">        <context:property-placeholder location="classpath:test.properties" />         <util:properties id="APP_PROP" location="classpath:test.properties" local-override="true"/>    </beans>    <!-- 本地環境配置文件 -->    <beans profile="local">        <context:property-placeholder location="classpath:local.properties" />         <util:properties id="APP_PROP" location="classpath:local.properties" local-override="true"/>    </beans>

    <!-- 生產環境配置文件 -->    <beans profile="local">        <context:property-placeholder location="classpath:production.properties" />         <util:properties id="APP_PROP" location="classpath:production.properties" local-override="true"/>    </beans>

util:properties是用@Value注解來引入配置文件中的變量

2.然后在web.xml文件中設置默認指向(我這里指向的是local)

<context-param>           <param-name>spring.profiles.default</param-name>           <param-value>local</param-value>      </context-param> 

3.然后就是激活你想要的配置文件

這里網上有很多方法 比如在web.xml文件里加入

<context-param>           <param-name>spring.profiles.default</param-name>           <param-value>local</param-value>      </context-param> 

考慮到盡量少的改動代碼,我這里在

tomcat 的啟動腳本中加入以下 JVM 參數 來激活

-Dspring.profiles.active="xxx"
本地開發環境用默認的local
測試環境的tomcat啟動腳本中加入
-Dspring.profiles.active="test"
生產環境的tomcat啟動腳本中加入
-Dspring.profiles.active="production"
好了,大功告成


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上栗县| 麦盖提县| 利辛县| 甘孜县| 石渠县| 松溪县| 鹤山市| 奈曼旗| 焦作市| 久治县| 怀远县| 桂阳县| 布拖县| 靖西县| 宝鸡市| 通河县| 固安县| 麻阳| 宜兴市| 黎城县| 凯里市| 新余市| 晋江市| 皮山县| 信宜市| 礼泉县| 类乌齐县| 怀仁县| 阿拉善盟| 资源县| 雷波县| 宁阳县| 张家港市| 巫溪县| 遂溪县| 方山县| 弥勒县| 渑池县| 紫阳县| 东乌| 陈巴尔虎旗|