Spring Note--ref attribute setting __spring

Source: Internet
Author: User
Specify the 3 modes of dependency with the properties of ref local\bean\parent
Local

If a bean is in the same XML file as the referenced bean and the referenced bean is named by ID, then the local property of ref can be used. This will allow the parser in the project to validate the Bean's ID earlier in parsing the XML document.

<bean id= "Signle" class= "Com.st.sig.Single" autowire= "Default" >
<property name= "Name" >
<ref local= "Mege"/>
</property>
</bean>
<bean id= "Mege" name= "Mege" class= "Com.st.sig.Mege" ></bean>
Bean

The Bean property of a ref element specifies that the referenced bean is the most common form in spring, allowing the bean to point to the same XML, or not to the same XML. The value of the Bean property can be the same as the id attribute of the bean referenced by the reference, or the same as the property of the bean referenced by the reference.

<bean id= "Signle" class= "Com.st.sig.Single" autowire= "Default" >
<property name= "Name" >
<ref bean= "Mege"/>
</property>
</bean>
<bean id= "Mege" name= "Mege" class= "Com.st.sig.Mege" ></bean>

Parent

When using the Parent property to specify the bean referenced by the reference, allow reference to the bean in the parent beanfactory or ApplicationContext of the current beanfactory or ApplicationContext. The value of the parent property can be the same as the name of the bean referenced by the reference or the same as the ID of the bean referenced by the reference

<bean id= "Signle" class= "Com.st.sig.Single" autowire= "Default" >
<property name= "Name" >
<ref parent= "Mege"/>
</property>
</bean>
<bean id= "Mege" name= "Mege" class= "Com.st.sig.Mege" ></bean>

same point for bean and Local:

Both beans and IDs can use the Bean's ID reference reference to reference the bean in the same XML

Different points of the

Bean and Local:
Specify dependencies with the Bean property to refer to the bean's name, and reference references to beans in different XML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.