【问题标题】:Spring - set of properties files to list of beansSpring - 一组属性文件到 bean 列表
【发布时间】:2013-09-13 23:16:53
【问题描述】:

我有一个包含相同键集的属性文件列表,例如:

database1.properties
databaseName=xxx
databasePassword=yyy

database2.properties
databaseName=zzzz
databasePassword=kkkk

使用 Spring,如何将两个属性文件存储在 2 个 bean 的列表中? bean 将有两个属性,databaseName 和 databasePassword。 这将用于 mule 流。

提前谢谢你

【问题讨论】:

    标签: spring mule


    【解决方案1】:

    试试下面的方法。

    <bean id="properties1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="ignoreUnresolvablePlaceholders" value="true"/>
       <property name="placeholderPrefix" value="${database1."/>
       <property name="locations">
        <list>
          <value>classpath:database1.properties</value>
        </list>
      </property>
    </bean>
    
    <bean id="properties2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="ignoreUnresolvablePlaceholders" value="false"/>
       <property name="placeholderPrefix" value="${database2."/>
       <property name="locations">
        <list>
          <value>classpath:database2.properties</value>
        </list>
      </property>
    </bean>
    

    您可以将 bean 的属性称为 database1.databaseNamedatabase2.databaseName

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2012-12-24
      相关资源
      最近更新 更多