Web App with Spring - Using properties in Service
I want to load few values from a proporties files that is in the /WEB-INF/ folder. I usually use this in my xml file when I develop a software using WebServices
<util:properties id="configProperties" location="classpath:/WEB-INF/config.properties" />
and then access to the value in Java using:
@Value("#{configProperties['clientURL']}")
private String clientURL;
public String urlClient() {
return clientURL;
}
But it doesn't work on my webapp, it's 开发者_StackOverflow中文版always returning the null
value.
WEB-INF
is not on the classpath. The classpath starts from WEB-INF/classes/
. So I would advise to place the properties file there (and change the location
property accordingly). The service layer should not know that it serves a web application (which has WEB-INF
)
I found the solution to my problem here: http://codingbone.wordpress.com/2010/02/28/how-to-load-properties-files-into-spring-and-expose-to-the-java-classes/
精彩评论