• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to inject property file in java.util.Properties member variable

 
Greenhorn
Posts: 24
Android MyEclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am very new to Spring 3 technology. My project requirement is to inject a property file in Spring 3. The intention is to load a property file into a

java.util.Properties

member variable using annotation.
Could somebody help me to achieve it?

Thanks in advance
Arun
 
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you can do is the following:

load the properties file in a PropertyPlaceHolderConfigurer in your XML:

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


You can also use the context-namespace for a more simple configuration.

When this is done, just use the @Value annotation.

e.g.: @Value("#{yourProperties.propertyKeyValue}")

I hope this helps, otherwise, the SpringSource reference guide offers more examples.

Regards,

Tim
 
Arun Vasu
Greenhorn
Posts: 24
Android MyEclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, this is what I was looking for
 
Tim Stockmans
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any time, I'm preparing for the SpringSource certification myself at the moment so I should know these things ;)

Kind regards,

Tim
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic