File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Arun Vasu
Greenhorn
Posts: 24
Android Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Tim Stockmans
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, this is what I was looking for
 
Tim Stockmans
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic