SmallSpring in <ref local= ""/> and <ref bean= ""/> Difference(2011-03-19 19:21:58)
reproduced
<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