2

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

database1.properties
databaseName=xxx
databasePassword=yyy

database2.properties
databaseName=zzzz
databasePassword=kkkk

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

先感谢您

4

1 回答 1

1

Try something like the following.

<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>

And you can refer to the properties at your beans as database1.databaseName or database2.databaseName

Hope this helps.

于 2013-09-13T15:16:53.137 回答