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

  • Spring Essentials
  • Shameer Kunjumohamed Hamidreza Sattari
  • 88字
  • 2021-07-16 13:05:48

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"/>
主站蜘蛛池模板: 高淳县| 绥滨县| 岱山县| 昭平县| 射阳县| 绥棱县| 突泉县| 四川省| 林甸县| 达孜县| 福安市| 和田市| 始兴县| 通河县| 景洪市| 阿拉善左旗| 大厂| 甘肃省| 浮梁县| 陇川县| 如皋市| 渭南市| 利津县| 福泉市| 德惠市| 五华县| 大田县| 新化县| 中西区| 天长市| 柘城县| 潮安县| 天全县| 威信县| 犍为县| 扎囊县| 大姚县| 万宁市| 屏山县| 通海县| 阿瓦提县|