问题描述:

I have been facing issue with following spring configuration. When i use txn:annotation alone it works fine, but when i try to use AOP it is causing exception.

Part of Spring config file:

 <tx:annotation-driven transaction-manager="transactionManager"

proxy-target-class="true"/>

<aop:aspectj-autoproxy >

<aop:include name="logging"/>

</aop:aspectj-autoproxy>

<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

....

</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource">

</bean>

<!--Aspect Annotation class-->

<bean id="logging" class="com.aop.LoggingAspect"></bean>

<!--Rest only other simple Business/DAO beans-->

Exception:

 org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': Bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' has been injected into other beans [org.springframework.transaction.config.internalTransactionAdvisor] in its raw version as part of a circular reference, but has eventually been wrapped. 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.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

at org.apache.catalina.core.StandardService.start(StandardService.java:525)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

I might be wrong at spring configuration, Please guide.

网友答案:

I can't see your beans definitions but it looks like you have circular dependencies. Because the names of the beans suggest that the problem occurs in spring beans and not your beans I guess you're defining things in a way that causes the problem. My guess is that you have some of your definitions defined in an XML and some defined with annotations. For example - you define a class with @Transactional annotation and for the same class you define an aspect using XML.

相关阅读:
Top