spring的事务管理配置如下:
.....
<!-- 事务管理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service,*Manager</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean>
......
程序在启动的时候,报错:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Bean with name 'transactionManager' has been
injected into other beans [transactionInterceptor] 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.
出现了循环依赖的错误,终于发现是
<property name="beanNames">
<value>*Service,*Manager</value>
</property>
里面的问题,transactionManager后边也是Manager。这样会把transactionInterceptor注入到transactionManager中,故将bean id="transactionManager"改成其他的名字不用Manager结尾,或者将*Manager改成其他的就不会出现这个错误了。
如果要改bean transactionManager 的名字,记得将transactionInterceptor中<property name="transactionManager" ref="transactionManager"/>
的ref="transactionManager"也改成对应的名字。
网上还发现了一种解决方法,发现也可行,不求甚解,先记下:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
将bean id="transactionManager"延迟加载。
分享到:
相关推荐
Spring循环依赖debug源码图
Spring源码最难问题:当Spring AOP遇上循环依赖.docx
Spring循环依赖.vsdx
spring bean循环依赖时序图详细的描述了spring的循环依赖关系,帮我们快速了解spring是如何优雅的进行处理的
在开发中,可能经常出现这种情况,只是我们平时并没有注意到原来我们写的两个类、甚至多个类相互依赖了,为什么注意不到呢?...这一切都是Spring的功劳,它在后面默默的为我们解决了循环依赖的问题。
spring boot 官方文档 PDF 版本
《spring源码之循环依赖和三级缓存》整理,本人水平有限,从网上找的资料整合之后做的,请辩证的看待其中内容。
spring-framework-reference参考文档,学习spring框架
Spring三级缓存解决循环依赖.pdf
spring-boot-reference spring-boot-reference spring-boot-reference
Spring集成SpringSecurity依赖包.也有springMVC的依赖包,直接下载引入就可用
spring文档 测试上传
Spring-Boot-Reference-Guide, Spring Boot Reference Guide中文翻译 -《Spring Boot参考指南》
spring-integration-reference
spring-batch-reference。
在开发中,可能经常出现这种情况,只是我们平时并没有注意到原来我们写的两个类、甚至多个类相互依赖了,为什么注意不到呢?...这一切都是Spring的功劳,它在后面默默的为我们解决了循环依赖的问题。
包含: 1.spring-boot-reference.pdf 2.spring-boot-reference.epub 3.Spring Boot Reference Guide.html