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

  • 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"/>
主站蜘蛛池模板: 祥云县| 眉山市| 仪陇县| 竹北市| 梁山县| 新源县| 德化县| 彭州市| 千阳县| 怀柔区| 肇源县| 雷波县| 香河县| 乡宁县| 财经| 清原| 高阳县| 夏邑县| 大庆市| 汶上县| 上虞市| 喀什市| 邯郸县| 毕节市| 墨江| 汝州市| 邓州市| 奉贤区| 安吉县| 康保县| 杨浦区| 瑞安市| 昔阳县| 阿拉善右旗| 河北省| 玉环县| 高雄市| 梁河县| 揭阳市| 绿春县| 张家口市|