• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic