![](/img/trans.png)
[英]How can I inject a property value into a Spring Bean which was configured using annotations?
[英]How can I inject a property value into an annotation configured spring mvc 3.0 controller
第一:我正在使用Spring 3.0
配置控制器类时出现问题。 控制器使用Web服务,我想使用.properties文件定义端点地址。
@Controller
public class SupportController {
@Value("#{url.webservice}")
private String wsEndpoint;
...
在我的应用程序上下文xml文件中,我定义了以下内容:
<context:property-placeholder location="/WEB-INF/*.properties" />
我一直在阅读文档,尝试使用不同的方法(例如添加前缀systemProperties。 ),但是我不断收到一条错误消息,告诉我它不存在。
在类型为“ org.springframework.beans.factory.config.BeanExpressionContext”的对象上找不到字段或属性“ url”
好。 我知道了。
现在,在控制器中:
@Value("#{settings['url.webservice']")
然后在上下文配置中,我有这个“帮助器bean”:
<util:properties id="settings"
location="/WEB-INF/supportweb.properties"></util:properties>
这也应该起作用:
@Value("${url.webservice}")
private String wsEndpoint;
我有此配置,它工作正常:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:application.properties</value>
</list>
</property>
</bean>
我以这种方式创造财产
@Value("${root.log.level}")
private String prop;
该字段已正确初始化为“ DEBUG”值。
您应该检查
<context:property-placeholder location="/WEB-INF/*.properties" />
在webmvc-config.xml中定义,您可以在其中创建@Controllers的实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.