windows環境下,tomcat部署、eclipse啓動實現war包讀取外部動態配置文件

 一、需求
     爲了使項目配置不受生產、測試、開發環境的影響,且更加可視化可維護配置文件,web項目的配置文件需要根據不同環境配置動態變更,不能直接寫死在war中,就需要我們實現war包可以讀取外部的配置文件。
 二、準備
  windows、eclipse、tomcat、spring配置
 三、實現
1、在war包外新建配置文件,如下圖

2、修改tomcat conf/catalina.properties 將配置文件路徑加入common.loader

3、在spring.xml配置中新加:

    <!-- 加載包外配置 -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
        <property name="location" value="file:E:/cms_dabao/config/spring_config.properties"/>
    </bean>

4、在spring.xml配置中引用包外的配置文件spring_config.properties

5、clean項目,重新啓動,over

文檔參考:https://blog.csdn.net/Mars93/article/details/78017209

                  https://blog.csdn.net/evilcry2012/article/details/51248513

發佈了13 篇原創文章 · 獲贊 4 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章