Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading properties file in spring mvc 3.0

 
venkateswarlu jinkala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic