弹簧属性(属性占位符)自动装配 [英] Spring properties (property-placeholder) autowiring

查看:153
本文介绍了弹簧属性(属性占位符)自动装配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的applicationContext.xml中

I have in my applicationContext.xml

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


<bean id="clientPreferencesManager" class="pl.bildpresse.bildchat2.business.ClientPreferencesManager" >
    <property name="clientApiUrl" value="${clientapi.url}" />     
</bean>

可以通过autowire做同样的事情吗?如下:

Is it possible to do the same by autowire ? Something like :

@Autowired
@Qualifier("${clientapi.url}")
public void setClientApiUrl(String clientApiUrl) {
    this.clientApiUrl = clientApiUrl;
}


推荐答案

您可以使用 @Value

@Value("${clientapi.url}") 
public void setClientApiUrl(String clientApiUrl) { 
    this.clientApiUrl = clientApiUrl; 
}

这篇关于弹簧属性(属性占位符)自动装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆