官术网_书友最值得收藏!

Externalizing properties with PropertyPlaceholderConfigurer

PropertyPlaceholderConfigurer is another convenient utility to externalize property values from a bean definition into a separate file that uses the standard java.util.Properties format. It replaces placeholders in XML bean definitions with matching property values in the configured property file, as shown here. This is the best way to externalize profile or environment-specific information such as datasource config, e-mail settings, and so on. The DevOps team will just edit these property files and never mess with your code:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" value="classpath:datasource.properties"/>
</bean>

<bean id="dataSource" destroy-method="close"
        class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>

Here is another simpler declaration of PropertyPlaceholder:

<context:property-placeholder location="classpath:datasource.properties"/>
主站蜘蛛池模板: 太原市| 宜城市| 达拉特旗| 噶尔县| 宜城市| 镇远县| 衡东县| 英山县| 富川| 河南省| 松滋市| 墨玉县| 鹤山市| 读书| 凤山县| 郸城县| 岗巴县| 成安县| 福清市| 白朗县| 拉萨市| 米泉市| 米脂县| 灵武市| 吴桥县| 宜君县| 和田市| 自治县| 庆城县| 洪湖市| 林西县| 隆尧县| 弥勒县| 荥阳市| 广平县| 思南县| 谷城县| 石河子市| 城固县| 溧水县| 上饶市|