This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Spring and the fly likes Reading properties file in spring mvc 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Reading properties file in spring mvc 3.0" Watch "Reading properties file in spring mvc 3.0" New topic

Reading properties file in spring mvc 3.0

venkateswarlu jinkala

Joined: Jul 19, 2011
Posts: 3
Hi all,

I am using Spring mvc 3.0 (Annotations). I am having a propert file like this

a = abc
b = bcd
c = cde

in my controller i am having a method getName(key) it has to return abc, bcd,cde ... according to the key.
i am not able to read the properties file
Tell me the steps to read the properties file.
can anyone please solve my problem as i am very new to spring framework.

Thanks in Advance.
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1290

You can simply use method to load a properties file. then use it in your method to fetch key-value pairs. You will not require Spring MVC concept here

~ abhay

Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17260

In your xml configuration use

<util:properties id="somthing" location="locationOfYourPropertiesFile">

then inject it into your controller class

Now your controller class will have the Properties object that you can call the getProperty() method on passing in the key.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Reading properties file in spring mvc 3.0