[英]Spring 3.0 @Value read from property file gettng exception on deployment
我正在尝试构建一个Spring 3.0应用程序版本3.1.0.RELEASE,我想从其中读取属性文件,并在Component类中使用从中读取的@Value注释。 为此,我进行了以下更改:在mvc-dispatcher-servlet.xml中:
<context:property-placeholder location="classpath:mediamonitoring.properties"/>
组件类:
@Component
公共类SomeHelper {
@Value("${baseUri}")
private String baseUri;
public String getBaseUri() {
return baseUri;
}
public void setBaseUri(String baseUri) {
this.baseUri = baseUri;
}
}
属性:
baseUri:http://localhost:8080/
并且我已经使用@Autowired注释将此帮助程序类连接到@service类。 当我构建和部署应用程序时,出现以下错误:
java.lang.IllegalArgumentException: Could not resolve placeholder 'baseUri'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
有什么我想念的东西吗,因为我只是遵循标准程序。
提前感谢您的帮助。
-瓦贝哈夫
使用=
代替:
作为分隔符
baseUri=http://localhost:8080/
无法发表评论,需要更多代表,因此请使用asnwer选项。 检查您在哪里放置了mediamonitoring.properties。 我的意思是,检查它是否在您的类路径中
用=
替换:
并使用#
代替$
#{baseUri}
您也可以尝试使用:
<util:properties id="props"
location="classpath:/yourproperties.properties" />
然后:
@Value("#{props['yourProperty']}")
假设您遵循使用ContextLoaderListener
和DispatcherServlet
的常规做法,请确保<context:property-placeholder location="classpath:mediamonitoring.properties"/>
处于正确的应用程序上下文中。 它将仅在相同应用程序上下文中的Bean上运行,而不在父或子上下文中的Bean上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.