Read Properties File In Spring Java

Read Property file in Spring - JAVA

This is a very quick post on how to read properties file in java using the Spring framework. Follow the below mentioned simple steps to achieve reading a property file using Spring:

1. Place the property file in src/main/resources folder.
2. Add the context:property-placeholder tag in your servlet.xml file

<context:property-placeholder location="classpath:file-path.properties, classpath:message-codes.properties" />

NOTE: use comma to register multiple properties file (as in above mentioned line of xml)

3. Now, use the annotation @Value(propertyName) in your java class to fetch the property
For instance,

@Value( "${file.type1.name}" )
    private static String fileName1;

The above lines of code will fetch the value of file.type1.name into static variable fileName1.

NOTE: Spring does not process static members. The member has to be an instance field.

This is it. You now know how to read properties file in java using Spring.

See you around.
Share on Google+

About Sujit Horakeri

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
    Blogger
    Facebook

26 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Online Training Java Online Training

    ReplyDelete
    Replies
    1. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!

      ETL Testing training in chennai| SAP MM training in chennai | Informatica training in chennai

      Delete
  2. The blog gave me idea to read properties file in spring My sincere thanks for sharing this post Please Continue to share this post
    Java Training in Chennai

    ReplyDelete
  3. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. Assam Ration Card Status

    ReplyDelete
  4. Great Article… I love to read your articles because your writing style is too good, it is very very helpful for all of us and I never get bored while reading your article because...
    Java Training in Marathahalli
    Python Training in Marathahalli

    ReplyDelete
  5. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog...No.1 IOS Training Institute in Chennai | Best Android Training Institute in Chennai | Java Training Institute in Chennai

    ReplyDelete
  6. Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog...No.1 IOS Training Institute in Chennai | Best Android Training Institute in Chennai | Java Training Institute in Chennai

    ReplyDelete
  7. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Java Training in Bangalore

    ReplyDelete
  8. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition"Devops Training in Bangalore" .

    ReplyDelete
  9. Thanks a lot for sharing this with all of us, I like it and we can communicate. Do you need buy app ratings and reviews. To boost app ranking and double app downloads now.

    ReplyDelete
  10. Nice post, Thanks for sharing the informative post and it's a worth read.
    Best VLSI Project Center in Chennai | VLSI Project Center in Velachery

    ReplyDelete
  11. Nice post I never seen this type of posts, I like it check it once Android Online Training Hyderabad

    ReplyDelete
  12. The information you shared is very effective for learners.

    Visit for a real time training for Java Training in Chennai | Best Java Training Institute in Chennai | Java Master Program Training in Chennai

    ReplyDelete
  13. It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Thank you for sharing.Final Year Java Project Centres Chennai|ME Project Centers Chennai.

    ReplyDelete
  14. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.
    java training in chennai | core java training in chennai

    ReplyDelete
  15. Very Nice!
    It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Thank you for sharing best Java Spring Training in Chennai | Vlsi Training in Chennai.

    ReplyDelete
  16. Very interesting blog which helps me to get the in depth knowledge about the technology, Thanks for sharing such a nice blog..
    Good discussion.
    Six Sigma Training in Abu Dhabi
    Six Sigma Training in Dammam
    Six Sigma Training in Riyadh

    ReplyDelete