Reputation: 845
I have some properties that I have put in a property file config.properties in the dir resources/config.config.properties.
I have the servlet.xml spring config file in the resources dir. It has this line
<util:properties id="nodeProperty"
location="classpath:config/config.properties" />
<context:property-placeholder properties-ref="nodeProperty"/>
In my controller I want to use the property from the file. Hence I have this line
@Autowired
@Value ("${paths.root}")
private String rootPath;
later in a web method I am saying
String rootPath = rootPath;
For this line I am getting the variable not initialized error for compiling.
If anyone has any solutions to this problem please let me know..
Upvotes: 1
Views: 171
Reputation: 845
Solved the issue using a q posted on stackoverflow. Added the following line in the servlet.xml
<util:properties id="someid" location="classpath:config/config.properties"/>
and then in my controller
private @Value("#{someid['paths.root']}") String rootPath;
Removed the @autowired and it worked!
Upvotes: 1