zoukankan      html  css  js  c++  java
  • 通过spring.profiles.active区分环境配置

    利用spring 的profile环境配置可以区分不同环境下的配置,但只能配置一个PropertyPlaceholderConfigurer,如果出现多个,后面的会覆盖前面的,导致配置找不到。

    配置文件的配置

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
      <!-- 不同的配置切换 -->
      <beans profile="dev">
        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="locations">
            <list>
              <value>classpath*:application-dev.properties</value>
            </list>
          </property>
        </bean>
      </beans>
    
      <beans profile="prod">
        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="locations">
            <list>
              <value>classpath*:application-prod.properties</value>
            </list>
          </property>
        </bean>
      </beans>
    
    </beans>
    

    application-prod.properties

    正式环境中的配置

    application-dev.properties

    测试环境中的配置

    切换环境

    可以在web.xml中配置默认环境

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

    切换配置时配置spring.profiles.active变量的值,可以配置在环境变量中也可以配置配置文件中,建议配置到环境变量中。

  • 相关阅读:
    Log4net日志记录、详细配置(自己使用>)
    C#中的委托
    关于asp.net假分页的删除操作的随笔
    XML完成小程序
    SQLServer理解copyonly备份操作
    c# 解析JSON的几种办法
    SQL删除重复数据方法
    Jquery 操作Html 控件 CheckBox、Radio、Select 控件
    关于SQL语句中SUM函数返回NULL的解决办法
    数据库里面DataTime时间类型字段,如果为null时
  • 原文地址:https://www.cnblogs.com/xuzhen97/p/11619945.html
Copyright © 2011-2022 走看看