gpt4 book ai didi

java - 如何将属性值注入(inject)注释配置的 spring mvc 3.0 Controller

转载 作者:IT老高 更新时间:2023-10-28 13:56:52 26 4
gpt4 key购买 nike

首先:我使用的是 Spring 3.0

我在配置 Controller 类时遇到问题。 Controller 使用 Web 服务,我想使用 .properties 文件定义端点地址。

@Controller
public class SupportController {

@Value("#{url.webservice}")
private String wsEndpoint;

...

在我的应用程序上下文 xml 文件中,我定义了这个:

<context:property-placeholder location="/WEB-INF/*.properties" />

我一直在阅读文档,尝试不同的方法(例如添加前缀 systemProperties.),但我不断收到一条错误消息,告诉我它不存在。

Field or property 'url' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'


好的。我想通了。

现在,在 Controller 中:

@Value("#{settings['url.webservice']")

然后在上下文配置中我有这个“帮助 bean”:

<util:properties id="settings" 
location="/WEB-INF/supportweb.properties"></util:properties>

最佳答案

这也应该有效:

@Value("${url.webservice}") 
private String wsEndpoint;

关于java - 如何将属性值注入(inject)注释配置的 spring mvc 3.0 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2055660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com