Spring:- ref 属性和 ref 标签有什么区别?
Spring:- What is the difference between ref attribute and ref tag?
我是 spring 的新手,一直在从官方文档中学习。我发现要使用 XML 配置注入依赖项,有两种方法可以声明 refs:-
<bean name="parentBean" class="com.example.ParentBean">
<property name="dependency1" ref="com.example.Dependency1"/>
</bean>
或者,我可以使用 ref 标签,例如:-
<bean name="parentBean" class="com.example.ParentBean">
<property name="dependency1">
<ref bean="com.example.Dependency1"/>
</property>
</bean>
这两个ref声明有什么区别吗?如果不是,为什么 spring 允许两种不同的方法?
提前致谢。
根据 XSD 中的评论(参见 <xsd:complexType name="propertyType">
):
ref
attribute: A short-cut alternative to a nested <ref bean='...'/>
.
这两个 ref 声明有什么区别吗?
没有
如果不是,为什么 spring 允许两种不同的方法?
方便。
核心目的是一样的。只是 标签有自己的属性:
When to use <ref bean> and when to use <ref local> in Spring?
我是 spring 的新手,一直在从官方文档中学习。我发现要使用 XML 配置注入依赖项,有两种方法可以声明 refs:-
<bean name="parentBean" class="com.example.ParentBean">
<property name="dependency1" ref="com.example.Dependency1"/>
</bean>
或者,我可以使用 ref 标签,例如:-
<bean name="parentBean" class="com.example.ParentBean">
<property name="dependency1">
<ref bean="com.example.Dependency1"/>
</property>
</bean>
这两个ref声明有什么区别吗?如果不是,为什么 spring 允许两种不同的方法?
提前致谢。
根据 XSD 中的评论(参见 <xsd:complexType name="propertyType">
):
ref
attribute: A short-cut alternative to a nested<ref bean='...'/>
.
这两个 ref 声明有什么区别吗?
没有
如果不是,为什么 spring 允许两种不同的方法?
方便。
核心目的是一样的。只是
When to use <ref bean> and when to use <ref local> in Spring?