Hi all.
I'm new to Spring and am having a nightmare trying to autoproxy both transaction handling and auditing advices.
I would like to add transaction support to my service classes and auditing to the database updates. These work fine individually and fine when wiring/weaving long-hand, however when both used at the same time using auto proxies I get the following exception:
org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'dataSource': Bean with name 'dataSource' has been injected into other beans [sessionFactory] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 49)
<snip>
My beans are defined as follows:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="transactionAutoProxy" class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>transactionAdvisor</value>
</list>
</property>
</bean>
<bean id="coffeeUserService"
class="com.XXX.service.CoffeeUserServiceImpl"
autowire="byName">
</bean>
<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor .NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="get*">
PROPAGATION_REQUIRED,ISOLATION_REPEATABLE_READ,rea dOnly
</prop>
<prop key="delete*">
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
</prop>
</props>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor .TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributeSource">
<ref bean="transactionAttributeSource"/>
</property>
</bean>
<bean id="transactionAdvisor" class="org.springframework.transaction.interceptor .TransactionAttributeSourceAdvisor">
<constructor-arg>
<ref bean="transactionInterceptor"/>
</constructor-arg>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="url"><value>XXX</value></property>
<property name="driverClassName"><value>XXX</value></property>
<property name="username"><value>XXX</value></property>
<property name="password"><value>XXX</value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/XXX/model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">XXX</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="coffeeUserDAO"
class="com.xxx.dao.CoffeeUserDAOImpl" autowire="byName">
</bean>
<bean id="dbAuditAdvice" class="com.xxx.advice.DatabaseAuditAdvice"/>
<bean id="dbAuditAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
<property name="patterns">
<list>
<value>.*[d|D]elete.*</value>
<value>.*[i|I]nsert.*</value>
<value>.*[u|U]pdate.*</value>
</list>
</property>
<property name="advice">
<ref bean="dbAuditAdvice"/>
</property>
</bean>
<bean id="dbAuditProxyCreator" class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*DAO</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>dbAuditAdvisor</value>
</list>
</property>
</bean>
Any help would be greatly appeciated.
Many thanks
Nick


Reply With Quote
