从SDN3迁移后在SDN4中配置链式事务管理器

时间:2015-11-07 15:45:48

标签: spring-data-neo4j-4

目前我正在尝试从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,所以迁移似乎是一个好主意。

1 个答案:

答案 0 :(得分:0)

通过此配置,我成功部署了我的应用程序:

$.contextMenu({
selector: 'span.context-menu',
build: function($triggerElement, e){
    var conditionalName = (x > 10) ? 'name1' : 'name2';
    return {
        callback: function(){},
        items: {
            menuItem: {name: conditionalName}
        }
    };
}

我还要将此元素添加到我的配置中:

@Bean(name = "transactionManager")
@Autowired
public PlatformTransactionManager neo4jTransactionManager(
        LocalContainerEntityManagerFactoryBean entityManagerFactory,
        Session session) throws Exception {
    Neo4jTransactionManager neoTransactionManager = new Neo4jTransactionManager(session);
    JpaTransactionManager mysqlTransactioNmanager = new JpaTransactionManager(entityManagerFactory.getObject());
    return new ChainedTransactionManager(mysqlTransactioNmanager,neoTransactionManager);
}