Read Properties Spring Application Context
There are many ways you could read value from properties file while using Spring framework. If you want to read properties from file during Spring context load please use below simple technique. To make something working I will create small maven project to show how to read properties from file:
- Create maven project name: LoadPropertyFromContext as full structure shown below:
This is just for reference you could download full project from bottom download link.
- Create properties file where you want to save all your project properties and in my case its javahonk-solace.properties where I wanted to save all my Solace properties:
- Create PropertyHolder.java class to hold whatever properties are needed to use during Application context load:
- Now create JavahonkReadPropertiesFromFile.java file which will load context and read properties:
- Download complete project LoadPropertyFromContext