spring事务问题排查记录一下

最近玩一个spring项目时报了一个很诡异的问题:错误如下:

2017-09-25 15:00:29.254 WARN  [main] [|] o.s.beans.factory.support.DefaultListableBeanFactory.getTypeForFactoryBean(): - Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'frsQueueInfoDao' defined in file [......class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': Error creating bean with name 'sqlSessionFactory' defined in file [.....\target\classes\beans\beans-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [.......\target\classes\beans\beans-datasource.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?

根据字面意思就是有循环依赖了,sqlSessionFactory 根据配置文件依赖dataSource,但是在创建dataSource时有问题,在dataSource配置的事务是

<bean name="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 启用注解式事务 -->
<tx:annotation-driven proxy-target-class="false" transaction-manager="transactionManager" />

问题困扰了很久,包括启动debug,看源码都没有解决问题...........

因为这个配置文件一直都没有动过,肯定是加了什么其他的代码导致的,想想最近加了neo4j驱动的代码,就从注解开始看如下:

@Configuration
@EnableNeo4jRepositories(basePackages = "com.....frs.repositories")
@EnableTransactionManagement

public class GraphDBConfiguration extends Neo4jConfiguration {}

其中一个注解是@EnableTransactionManagement 这个路径是

import org.springframework.transaction.annotation.EnableTransactionManagement;

经查:

@EnableTransactionManagement

@EnableTransactionManagement注解开启注解式事务的支持。

注解@EnableTransactionManagement通知Spring,@Transactional注解的类被事务的切面包围。这样@Transactional就可以使用了。

根据现在neo4j的运用,我们不需要开启事务,所有注销此注解,再运行没有上述问题,

先记录一下上述解决问题及过程。具体原因后续更新

猜你喜欢

转载自blog.csdn.net/wangdonghello/article/details/78091896
今日推荐