【问题标题】:How to read environment property into xml如何将环境属性读入xml
【发布时间】:2017-04-24 03:49:45
【问题描述】:

我在应用程序中有环境属性,例如 portal.db.pwd。 现在我想把它读入xml,比如:

<bean id="testBean" class="com.example.service.TestBean" depends-on="customerService" lazy-init="true">
    <!--        <property name="message" value="# {systemProperties['portal.db.password']}" /> -->
        <property name="message" value="${portal.db.password}" />
</bean>

尝试两种方法,都行不通。

【问题讨论】:

    标签: java xml spring environment-variables


    【解决方案1】:

    您必须添加属性占位符配置才能在您的 XML 文件中使用这些属性,

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location">
        <value>yourFile.properties</value>
      </property>
    </bean>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 2016-02-01
      • 1970-01-01
      • 2018-10-10
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多