SpEL表达式的#root对象是BeanexpressionContext,您可以
getObject()在该上下文上调用方法;如果未声明bean,则返回null。
<property name="bar" value="#{getObject('bar')}" />注意:之所以使用
valuenot,
ref是因为它返回的是bean,而不是bean的定义。
这是来自的代码
getObject()
public Object getObject(String key) { if (this.beanFactory.containsBean(key)) { return this.beanFactory.getBean(key); } else if (this.scope != null){ return this.scope.resolveContextualObject(key); } else { return null; }}


