Circular depedency issue - one with constructor arg, one with setter
Connor Barry <[email protected]> Sun, 09 May 2010 11:38:15 -0600
| Newsgroups | gmane.comp.java.springframework.user |
|---|---|
| Message-ID | <[email protected]> |
I have two beans, defined as:
<bean id="cspTransportFactory"
class="com.mycompany.CSPCompatibleTransportFactory">
<constructor-arg index="0" ref="cspClient" />
</bean>
<bean id="cspClient" class="org.apache.xmlrpc.client.XmlRpcClient" >
<property name="transportFactory" ref="cspTransportFactory" />
</bean>
Spring is choking at startup with error:
Caused by:
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'cspTransportFactory': Requested bean is
currently in creation: Is there an unresolvable circular reference?
Previously I was able to construct these beans by injecting instances
into one another before calling setter method:
XmlRpcClient client = new XmlRpcClient();
CSPCompatibleTransportFactory tf = new
CSPCompatibleTransportFactory(client);
client.setTransportFactory(tf);
Note that I don't have control over the fact that the
cspTransportFactory uses constructor injection because I'm extending
another API class. Spring can construct a circular dependency in the
same matter when two classes use strictly setter injection. Shouldn't it
be able to do the same when one of the two classes uses CI?
------------------------------------------------------------------------------