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.
Connect with him on:
    Blogger
    Facebook

10 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
  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