I've created a fairly simple test setup which can replication the problem we're experiencing in our system.
We have a facade (called TestFacade here) which is made transactional using the TransactionProxyFactoryBean. The facade has a setter property to the CompanyDao. The CompanyDao finally has a constructor which takes a Hibernate SessionFactory as argument (autowire=constructor).
Configuration file:
When the configuration only contains the Dao, everything works nicely (with the dao). When the facade and the TransactionProxyFactoryBean gets added to the mix we get the following exception:Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property> <property name="url"><value>jdbc:mysql://localhost/ModelTestDB</value></property> <property name="username"><value>root</value></property> <property name="password"><value>root</value></property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"><ref local="dataSource"/></property> </bean> <bean id="companyDao" class="org.test.CompanyDao" autowire="constructor"> </bean> <bean id="testFacadeTarget" class="org.test.TestFacade"> <property name="companyDao"> <ref local="companyDao"></ref> </property> </bean> <bean id="testFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager"></ref> </property> <property name="target"> <ref local="testFacadeTarget"></ref> </property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="mappingResources"> <list> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop> </props> </property> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> </beans>
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testFacade' defined in class path resource [org/test/application-context.xml]: Can't resolve reference to bean 'testFacadeTarget' while setting property 'target'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testFacadeTarget' defined in class path resource [org/test/application-context.xml]: Can't resolve reference to bean 'companyDao' while setting property 'companyDao'; nested exception is
org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'companyDao': Requested bean is already currently in creation
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testFacadeTarget' defined in class path resource [org/test/application-context.xml]: Can't resolve reference to bean 'companyDao' while setting property 'companyDao'; nested exception is org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'companyDao': Requested bean is already currently in creation
org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'companyDao': Requested bean is already currently in creation
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:898)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:832)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:898)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:832)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.Abstract BeanFactory.getType(AbstractBeanFactory.java:345)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.isBeanTypeMatch(DefaultListable BeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:157)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:144)
at org.springframework.beans.factory.BeanFactoryUtils .beansOfTypeIncludingAncestors(BeanFactoryUtils.ja va:160)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.findMatchingBeans(DefaultListab leBeanFactory.java:313)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createArgumentArray(Abs tractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:433)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:238)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:236)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:304)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:80)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:56)
at org.test.TestFacadeTest.testCreateNewCompany(TestF acadeTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154 )
at junit.framework.TestCase.runBare(TestCase.java:127 )
at junit.framework.TestResult$1.protect(TestResult.ja va:106)
at junit.framework.TestResult.runProtected(TestResult .java:124)
at junit.framework.TestResult.run(TestResult.java:109 )
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:186)


Reply With Quote