Reputation: 560
Im trying to read a properties file from an external location and I am trynig to use the contextPath name as the file's names beacuse I will run multiple instances of the app on he same server. I'm currently using SpringFramework 3.1.4
<context:property-placeholder location="file:/configFolder/#{servletContext.contextPath}.properties" />
the file name ends up being /configFolder/#{servletContext.contextPath}.properties
It does not replace the variable
is there another way to get this value?
Upvotes: 1
Views: 1124
Reputation: 85779
#{servletContext.contextPath}
is a variable only known in JSP and Facelets through Expression Language. This won't work in Spring. You should put your configuration file inside a resource folder in your jar and retrieve it from there instead.
You state that this worked in other projects but that was because Spring supported a variable called servletContext
(which IMO is wrong). Looks like Spring MVC 3.2 doesn't support this anymore, as explained here: Resolving servletContext.contextPath Expression in Spring 3.2.
Upvotes: 2
Reputation: 36
Try:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/config/#{servletContext.contextPath}.properties" />
</bean>
Upvotes: 2