Announcement Announcement Module
Collapse
No announcement yet.
Problem using parent abstract template bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using parent abstract template bean

    Hi,

    I am currently in the process of determining the "best" way to introduce the usage of Spring into our development processes and teams.
    As part of that, I am exploring the several ways Spring offers to define and configure "enterprise aspects" and apply them to business logic beans:
    • - Direct usage of ProxyFactoryBean
      - TransactionProxyFactoryBean + preInterceptors / postInterceptors
      - Declarative services approach with DefaultAdvisorAutoProxyCreator + source code annotations
      - Declarative services approach with BeanNamesAutoProxyCreator + source code annotations
      - "EnterpriseBeanTemplate" (abstract template bean) used as parent of the enterprise bean components
      - etc
    Everything was working fine until I tried the abstract template bean approach. The setup is as follows:
    infrastructureContext.xml:
    Code:
    <beans>
    
    	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName"><value>...omitted...</value></property>
    	</bean>
    	
    	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource"><ref local="dataSource" /></property>
    	</bean>
    	
    </beans>
    declarativeServices.xml:
    Code:
    <beans>
    
    	<!-- COMMENTED OUT
    	<bean id="autoProxyCreator"
    		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
    	</bean>
    	-->
    
    	<bean id="transactionAttributeSource"
    		class="org.springframework.transaction.interceptor.AttributesTransactionAttributeSource"
    		autowire="constructor">
    	</bean>
    	
    	<bean id="transactionInterceptor"
    		class="org.springframework.transaction.interceptor.TransactionInterceptor"
    		autowire="byType">
    	</bean>
    	
    	<bean id="transactionAdvisor"
    		class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"
    		autowire="constructor">
    	</bean>
    	
    	<bean id="attributes"
    		class="org.springframework.metadata.commons.CommonsAttributes"
    	/>
    	
    	<bean id="TraceInterceptor" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />
    	
    </beans>
    applicationContext.xml:
    Code:
    <beans>
    
    	<bean id="EnterpriseBeanTemplate"
    		class="org.springframework.aop.framework.ProxyFactoryBean"
    		abstract="true"
    	>
    		<property name="interceptorNames">
    			<list>
    				<value>TraceInterceptor</value>
    				<value>transactionAdvisor</value>
    			</list>
    		</property>
    	</bean>
    	
    	<bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    		<property name="configLocation"><value>compatest5/sqlmap-config.xml</value></property>
    	</bean>
    
    	<bean id="dao.Peticiones" class="domain.impl.PeticionesDAO">
    		<property name="dataSource"><ref bean="dataSource" /></property>
    		<property name="sqlMapClient"><ref local="sqlMap" /></property>
    	</bean>
    	
    	<bean id="GestorPeticiones" parent="EnterpriseBeanTemplate">
    		<property name="proxyInterfaces"><value>domain.GestorPeticiones</value></property>
    		<property name="target">
    			<bean class="domain.impl.GestorPeticiones">
    				<property name="dao"><ref local="dao.Peticiones" /></property>
    			</bean>
    		</property>
    	</bean>
    	
    	<bean id="ModuloAsincrono" parent="EnterpriseBeanTemplate">
    		<property name="proxyInterfaces"><value>domain.ModuloAsincrono</value></property>
    		<property name="target">
    			<bean class="domain.impl.ModuloAsincrono" />
    		</property>
    	</bean>
    	
    </beans>
    Unfortunately I get the following exception during initialization:
    Code:
    org.springframework.beans.factory.BeanCurrentlyInCreationException&#58; Error creating bean with name 'transactionAttributeSource'&#58; Requested bean is currently in creation &#40;circular reference when autowiring constructor?&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;195&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;176&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;145&#41;
    	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors&#40;BeanFactoryUtils.java&#58;163&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findMatchingBeans&#40;DefaultListableBeanFactory.java&#58;338&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType&#40;AbstractAutowireCapableBeanFactory.java&#58;707&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;641&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;288&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;176&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;145&#41;
    	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors&#40;BeanFactoryUtils.java&#58;163&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findMatchingBeans&#40;DefaultListableBeanFactory.java&#58;338&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createArgumentArray&#40;AbstractAutowireCapableBeanFactory.java&#58;594&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor&#40;AbstractAutowireCapableBeanFactory.java&#58;463&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;268&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.aop.framework.ProxyFactoryBean.createAdvisorChain&#40;ProxyFactoryBean.java&#58;324&#41;
    	at org.springframework.aop.framework.ProxyFactoryBean.setBeanFactory&#40;ProxyFactoryBean.java&#58;197&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;301&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getType&#40;AbstractBeanFactory.java&#58;347&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.isBeanTypeMatch&#40;DefaultListableBeanFactory.java&#58;235&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;163&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType&#40;DefaultListableBeanFactory.java&#58;145&#41;
    	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors&#40;BeanFactoryUtils.java&#58;163&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findMatchingBeans&#40;DefaultListableBeanFactory.java&#58;338&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createArgumentArray&#40;AbstractAutowireCapableBeanFactory.java&#58;594&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor&#40;AbstractAutowireCapableBeanFactory.java&#58;463&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;268&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;236&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;261&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;317&#41;
    	at org.springframework.web.context.support.XmlWebApplicationContext.refresh&#40;XmlWebApplicationContext.java&#58;131&#41;
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext&#40;ContextLoader.java&#58;156&#41;
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext&#40;ContextLoader.java&#58;97&#41;
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized&#40;ContextLoaderListener.java&#58;48&#41;
    	at org.apache.catalina.core.StandardContext.listenerStart&#40;StandardContext.java&#58;3271&#41;
    	at org.apache.catalina.core.StandardContext.start&#40;StandardContext.java&#58;3613&#41;
    	at org.apache.catalina.core.ContainerBase.addChildInternal&#40;ContainerBase.java&#58;821&#41;
    	at org.apache.catalina.core.ContainerBase.addChild&#40;ContainerBase.java&#58;807&#41;
    	at org.apache.catalina.core.StandardHost.addChild&#40;StandardHost.java&#58;595&#41;
    	at org.jboss.web.tomcat.tc4.EmbeddedTomcatService.createWebContext&#40;EmbeddedTomcatService.java&#58;549&#41;
    	at org.jboss.web.tomcat.tc4.EmbeddedTomcatService.performDeploy&#40;EmbeddedTomcatService.java&#58;309&#41;
    	at org.jboss.web.AbstractWebContainer.start&#40;AbstractWebContainer.java&#58;428&#41;
    	at org.jboss.deployment.MainDeployer.start&#40;MainDeployer.java&#58;832&#41;
    	at org.jboss.deployment.MainDeployer.start&#40;MainDeployer.java&#58;824&#41;
    	at org.jboss.deployment.MainDeployer.deploy&#40;MainDeployer.java&#58;642&#41;
    	at org.jboss.deployment.MainDeployer.deploy&#40;MainDeployer.java&#58;605&#41;
    	at sun.reflect.GeneratedMethodAccessor18.invoke&#40;Unknown Source&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke&#40;ReflectedMBeanDispatcher.java&#58;284&#41;
    	at org.jboss.mx.server.MBeanServerImpl.invoke&#40;MBeanServerImpl.java&#58;546&#41;
    	at org.jboss.mx.util.MBeanProxyExt.invoke&#40;MBeanProxyExt.java&#58;177&#41;
    	at $Proxy6.deploy&#40;Unknown Source&#41;
    	at org.jboss.deployment.scanner.URLDeploymentScanner.deploy&#40;URLDeploymentScanner.java&#58;302&#41;
    	at org.jboss.deployment.scanner.URLDeploymentScanner.scan&#40;URLDeploymentScanner.java&#58;476&#41;
    	at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan&#40;AbstractDeploymentScanner.java&#58;201&#41;
    	at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop&#40;AbstractDeploymentScanner.java&#58;212&#41;
    	at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run&#40;AbstractDeploymentScanner.java&#58;191&#41;
    No doubt I am doing something awfully wrong but got no clue... :?

    Any pointers in the right direction are much appreciated, thank you.
    Fernando

  • #2
    Hi Fernando,

    as the Exception says, You have a circular dependency that results from the autowirie config of the 'transactionAttributeSource' bean.

    Probably You already know what it means: the constructor of AttributesTransactionAttributeSource has a dependency argument which depends back on your transactionAttributeSource bean.

    Try to resolve the circular reference and it may work.

    I don't think, that the abstract parent bean is the direct cause of your problems, but autowiring is to some degree "automagic" and therefore vulnerable to side effects caused by introducing new beans.

    Cheers,
    Felix

    Comment


    • #3
      Thank you Felix, you were right.

      The problem lies in the autowiring stuff; it just manifested itself only when I took the parent template bean approach. I changed all the transaction-whatever beans to be manually configured and now it all works great!

      Best regards,
      Fernando

      Comment

      Working...
      X