zoukankan      html  css  js  c++  java
  • Spring 数据库连接池读取系统环境变量作为参数

    原来是写在一个properties文件里面,后来项目要部署的的确太多了,每次更改不太方便,就想把这些固定不变的信息写在当地的环境变量里面

    原先是这样的:引用的所有信息在jdbc.properties

    <bean id="propertyConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean>
     
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
    </bean>

    更改后是利用 org.springframework.context.support.PropertySourcesPlaceholderConfigurer

    此类实现了EnvironmentAware 接口,可以实现读取系统环境变量

    linux修改 /etc/profile  

    新增 export jdbc_url = 你的url

       export jdbc_usrname = 你的usrname

    <bean id="propertyConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean>
     
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="url" value="${jdbc_url}"/>
        <property name="username" value="${jdbc_username}"/>
    </bean>

    这样就可以读取系统环境变量了~~~~

  • 相关阅读:
    简单好用的日历排期控件
    Ext.js create store
    Ext.js页面添加元素
    Ext.js Tree
    前端设计的七大法则
    如何写软件开发相关文档,它包含哪些种类和内容
    行内文字末尾下降
    正则表达式
    滚动加载数据
    location.hash来保持页面状态
  • 原文地址:https://www.cnblogs.com/qiaoyihang/p/6674016.html
Copyright © 2011-2022 走看看