0

I've been using org.springframework.beans.factory.config.PropertyPlaceholderConfigurer and in my experience ("citation needed" LOL) it sets the property values globally.

Is there a way to specify different PropertyPlaceholderConfigurer instances for different beans within the same application context xml?

My current code is similar to

<bean id="a" class="X">
  <property name="foo" value="bar"/>
  <property name="many" value="more"/>
</bean>

<bean id="b" class="X">
  <property name="foo" value="baz"/>
  <property name="number_of_properties" value="a zillion"/>
</bean>

I would like to do something like (pseudo-code below):

<bean id="a" class="X">
  ... parse the contents of "a.properties" here ...
</bean>

<bean id="b" class="X">
  ... parse the contents of "b.properties" here ...
</bean>

The above is non-working pseudo code to illustrate the concept; the point being, I want a different properties file to feed each bean.

WHY?

I want to have those specific properties in separate properties file and not in XML.

Alex R
  • 11,364
  • 15
  • 100
  • 180

1 Answers1

0

I think the following link can br helpful to you. Reference Link

where @Value("${my.property.name}") annotation is used to bind the property file to a variable of type Properties which will reside in your bean class where you intend to use that properties file.

and you can define multiplte proprtiesplaceholder as below:

<bean id="myProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>classpath*:my.properties</value>
    </list>
  </property>
</bean>

and use the id as reference in your bean variable to initialize properties file to the bean.

And it will be handy to include with placeholder bean.

Kindly refer Importance of Unresolvable Placeholder link for detailed info regarding its usage.

Hope this was helpful.

srikanth r
  • 302
  • 3
  • 20