【发布时间】:2015-11-07 15:45:47
【问题描述】:
目前我正在尝试从 SDN3 迁移到 SDN4。在我的项目中,我使用了两个数据库:Neo4j 和 MySQL,所以我最终使用了链式事务管理器。但是,迁移后我的配置有问题。在迁移之前我有这个:
@Bean(name = "transactionManager")
@Autowired
public PlatformTransactionManager neo4jTransactionManager(
LocalContainerEntityManagerFactoryBean entityManagerFactory, GraphDatabaseService graphDatabaseService)
throws Exception {
JtaTransactionManager neoTransactionManager = new JtaTransactionManagerFactoryBean(graphDatabaseService)
.getObject();
neoTransactionManager.setRollbackOnCommitFailure(true);
neoTransactionManager.setAllowCustomIsolationLevels(true);
JpaTransactionManager mysqlTransactioNmanager = new JpaTransactionManager(entityManagerFactory.getObject());
return new ChainedTransactionManager(mysqlTransactioNmanager, neoTransactionManager);
}
现在我有这样的东西:
@Bean(name = "transactionManager")
@Autowired
public PlatformTransactionManager neo4jTransactionManager(
LocalContainerEntityManagerFactoryBean entityManagerFactory, Neo4jTransactionManager neo4jTransactionManager)
throws Exception {
Neo4jTransactionManager neoTransactionManager = neo4jTransactionManager;
JpaTransactionManager mysqlTransactioNmanager = new JpaTransactionManager(entityManagerFactory.getObject());
return new ChainedTransactionManager(mysqlTransactioNmanager, neoTransactionManager);
}
但是,由于这个异常,项目无法部署在服务器上:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public org.springframework.transaction.PlatformTransactionManager com.project.config.ApplicationConfig.neo4jTransactionManager(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean,org.springframework.data.neo4j.transaction.Neo4jTransactionManager) throws java.lang.Exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.neo4j.transaction.Neo4jTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
当提到配置的一部分时,项目已正确部署,但显然在保存到 MySQL 数据库期间丢失事务存在异常。 我应该如何在 SDN4 中配置这个链式事务管理器?现在很难找到任何例子,因为 SDN4 是最近才出现的,我确实需要 Neo4j 处于独立模式,所以迁移似乎是个好主意。
【问题讨论】: