The IDREF element is used to pass the ID of the other bean in the container to the <constructor-arg/> or <property/> element, while providing error-validation functionality.
<bean id= "Thetargetbean" class= "..."/>
<bean id= "Theclientbean" class= "...". >
<property name= "TargetName" >
<idref bean= "Thetargetbean"/>
</property>
</bean>
The above bean definition fragment is completely equivalent to the following fragment (at run time)
<bean id= "Thetargetbean" class= "..."/>
<bean id= "Client" class= "..." >
<property name= "TargetName" value= "Thetargetbean"/>
</bean>
It's also the idref. I can get the value of the Bean's name (a string) in the spring container, not an instance of the bean.
The function of the IDREF element is similar to that of <value>, that is, the IDREF function is much more validated, which reduces the probability of writing errors in the configuration. In addition to the <idref bean= ""/>, if the referenced bean is in the same XML file, and the bean's name is the bean's ID, you can use the <IDFEF local= ""/> This property allows the XML parser to validate the referenced bean when parsing the XML.
In the value method, the TargetName property value passed to the client bean is not validated. Any input errors are found only when the client bean is actually instantiated (possibly with fatal errors).
And ref is the instance that gets the bean. Used to implement the injection function.
If just want to get the name of the bean using IDREF
Use the IDREF tag to allow the container to verify that the referenced bean exists at deployment time.
Ref has three properties: local, parent, Bean, as follows: Local can only specify the name of the object defined in the same configuration file as the currently configured object, and parent can only specify the object reference that is defined in the parent container of the current container; So, in all cases, it's OK to use the bean directly to specify the object reference.