At some point you need to specify an external object, there you can not avoid this. However, you can port this to Java and from XML by adding the factory method to A, which creates an internal one B:
public class A {
public class B {}
B b;
public void setB(B b) {this.b = b;}
public B createB() {return new B();}
}
And then you can do:
<bean id="a" class="test.A">
<property name="b">
<bean id="b" factory-bean="a" factory-method="createB"/>
</property>
</bean>
So XML is simpler, but java is more complex. Spring is smart enough not to worry about seemingly circular links.
Take your choice, you need to do one or the other.
source
share