春季:如何通过XML将属性值注入Bean? [英] Spring: How to inject a property value into the bean via XML?
本文介绍了春季:如何通过XML将属性值注入Bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有注入字段值的bean.它工作正常.我使用批注要求 Spring
将 properties
中的值注入到bean中.
I have a bean with injected field value. It works just fine. I use annotation to ask Spring
to inject value from properties
into the bean.
public class MyBean {
@Value("${app.settings.value}")
private String value;
}
如何通过XML执行相同的操作?我尝试使用 value =#{}"
进行注入.
How can I do the same via XML? I've tried to inject using value="#{}"
.
<bean id="myBean" class="com.test.MyBean">
<property name="value" value="{app.settings.value}"/>
</bean>
但是我的方法行不通.
推荐答案
尝试一下:
<bean id="myBean" class="com.test.MyBean">
<property name="value" value="${app.settings.value}"/>
</bean>
语法与Java配置相同-前缀为 $
符号.
The syntax is the same as for java config - prefixed with the $
sign.
这篇关于春季:如何通过XML将属性值注入Bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文