Hello,
I am using autowire by-name and setter injection.
If I declare a bean in the following way:
<bean id="xService" class="a.b.c.XServiceBean"/>
the app deploys correctly (on JBoss).
If (for a certain reason) I try to do the following:
<bean id="xServiceFactory"
class="org.springframework.beans.factory.config.Ob jectFactoryCreatingFactoryBean">
<property name="targetBeanName" value="xServiceBean"/>
</bean>
<bean id="xService"
factory-method="getObject"
factory-bean="xServiceFactory"
/>
<bean id="xServiceBean" class="a.b.c.XServiceBean"/>
The app does not deploy because of a circular reference, and here is the exception trace:
Error creating bean with name 'xService' defined in URL
[file:(path)/someSpringConfig.xml]: Instantiation of bean failed; nested
exception is org.springframework.beans.factory.BeanDefinitionSt oreException :
Factory method [public java.lang.Object
org.springframework.beans.factory.config.ObjectFac toryCreatingFactoryBean$1.getObject()
throws org.springframework.beans.BeansException] threw exception; nested
exception is org.springframework.beans.factory.BeanCurrentlyInC reationException
: Error creating bean with name 'Singleton 'xService' is already in creation':
Requested bean is currently in creation: Is there an unresolvable circular
reference?
I would like to go for the solution with the ObjectFactoryCreatingFactoryBean,
I'm looking for ideas as to what could I try to fix the circular reference problem.
Thanks,
Zubrowka


Reply With Quote
but I suppose the problem occurs because the XServiceBean class contains a reference to a different service, say YService. YServiceBean, which implements YService, has a reference to XService:
