ref vs idref attributes in spring bean declaration ref vs idref attributes in spring bean declaration spring spring

ref vs idref attributes in spring bean declaration


Here is a little more verbose example, suppose you have two beans A and B:

<bean class="A" id="a" /><bean class="B"/>    <constructor-arg>        <ref bean="a"/>        <idref bean="a"/>    </constructor-arg></bean>

In this case B would have a constructor that would look like this:

public B(A a, String string) {     string.equals("a"); //true}

So with ref you can reference an object and with idref you just reference the name of the bean


ref is used to pass the bean that the ref refers to.
idref is used to pass the name of the bean (as a String) that is referred to.

http://forum.springsource.org/showthread.php?t=74355


idref must point to a real bean. and the format should be <idref bean=""/>