File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How to inject property file in java.util.Properties member variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to inject property file in java.util.Properties member variable" Watch "How to inject property file in java.util.Properties member variable" New topic
Author

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

Arun Vasu
Greenhorn

Joined: Oct 05, 2010
Posts: 24

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
member variable using annotation.
Could somebody help me to achieve it?

Thanks in advance
Arun
Tim Stockmans
Greenhorn

Joined: Feb 22, 2011
Posts: 7

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

Joined: Oct 05, 2010
Posts: 24

Thanks Tim, this is what I was looking for
Tim Stockmans
Greenhorn

Joined: Feb 22, 2011
Posts: 7

Any time, I'm preparing for the SpringSource certification myself at the moment so I should know these things ;)

Kind regards,

Tim
 
 
subject: How to inject property file in java.util.Properties member variable
 
Similar Threads
Injection in Spring
Help needed to set up Spring IOC in a web application
read properties in my java application defined in spring bean "PropertyPlaceholderConfigurer"
persistent system variable creation...
Spring Property reading