Re: Circular depedency issue - one with constructor arg, one with setter
Rob Butler <[email protected]> Mon, 10 May 2010 05:58:02 -0700 (PDT)
| Newsgroups | gmane.comp.java.springframework.user |
|---|---|
| Message-ID | <[email protected]> |
Think about it. Could you do it in Java code? No. So why would you expect Spring to be able to do it? In your example you are passing at least one in a setter. The same thing should be possible in Spring. In the Spring config you are trying to construct two objects and pass them to each other simultaneously. You couldn't do that in Java either. Rob ----- Original Message ---- > From: Connor Barry <[email protected]> > To: List for Spring users <[email protected]> > Sent: Sun, May 9, 2010 1:38:15 PM > Subject: [Springframework-user] Circular depedency issue - one with constructor arg, one with setter > > 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? ------------------------------------------------------------------------------ _______________________________________________ Springframework-user > mailing list > href="mailto:[email protected]">[email protected] > href="https://lists.sourceforge.net/lists/listinfo/springframework-user" > target=_blank > >https://lists.sourceforge.net/lists/listinfo/springframework-user ------------------------------------------------------------------------------