my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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
Author

Reading properties file in spring mvc 3.0

venkateswarlu jinkala
Greenhorn

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

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

abc.properties

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: 1080
    
    1


You can simply use System.properties() 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 Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading properties file in spring mvc 3.0
 
Similar Threads
combination of strings
How to refresh a StringBuffer object for creating a HashMap object
vector elements asssignment to variables for storing to db
Reading XML Documents Using DOM...
How to Group a Collection of Pojo's based on some pojo property?