Spring in <ref local= ""/> and <ref bean= ""/> Difference

Source: Internet
Author: User

SmallSpring in <ref local= ""/> and <ref bean= ""/> Difference(2011-03-19 19:21:58) reproduced
Tags: gossip



<ref local= "xx"/>
Use the "local" property to specify that the target is the index that points to the "local" value of the corresponding ID attribute value within the same file
The value of the "local" property must be the same as the target Bean's ID property. If there are no matching elements within the same file, the XML parser will prompt an error. Similarly, if the target is within the same XML file, using the "local" variable is the best choice (in order to know the error as early as possible)

<ref bean= "xx"/>
Specifying the target bean as the "bean" attribute is the most general form, which allows the creation of beans indexed to any bean within the same container (whether or not in the same XML file) or in a parent container. The value of the Bean property can be the same as the ID property of the target bean, or it can be the same as a value within the Name property of the target bean

    • So to speak, <ref bean= ""/> is to look for the bean in the global; <ref local= ""/> is looking for beans in this XML file

    • <ref> provides properties for the following aspects:

1) Bean: In the current Spring XML configuration file, or in another JavaBean in the same beanfactory (ApplicationContext).
2) Local: In the current Spring XML configuration file. The JavaBean it relies on must exist in the current Spring XML configuration file. If the Spring IDE is used, the JavaBean that it relies on can be validated at compile time. Based on the local approach, developers can use the benefits provided by the XML itself for validation.
3) Parent: Specifies the parent JavaBean definition for which it depends.

Spring in <ref local= ""/> and <ref bean= ""/> Difference

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.