开发者

Web App with Spring - Using properties in Service

开发者 https://www.devze.com 2023-03-25 01:55 出处:网络
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

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消