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

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"/>
主站蜘蛛池模板: 丹江口市| 咸宁市| 台前县| 江山市| 金堂县| 大名县| 马山县| 彰化县| 乌拉特前旗| 高要市| 西乌珠穆沁旗| 甘肃省| 盐山县| 永丰县| 永丰县| 龙游县| 遂昌县| 安图县| 南涧| 峨山| 兴安盟| 祁阳县| 高淳县| 城市| 乐业县| 北流市| 蓬莱市| 新余市| 昌图县| 鞍山市| 曲周县| 吉木乃县| 榕江县| 安乡县| 盐山县| 马山县| 西青区| 宣汉县| 左云县| 偏关县| 慈利县|