【问题标题】:Configuration of chained transaction manager in SDN4 after migration from SDN3从 SDN3 迁移后 SDN4 中链式事务管理器的配置
【发布时间】: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 处于独立模式,所以迁移似乎是个好主意。

【问题讨论】:

    标签: spring-data-neo4j-4


    【解决方案1】:

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

    @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);
    }
    

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

    @Override
    @Bean
    @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      • 2010-10-18
      • 2014-02-22
      • 2015-04-24
      相关资源
      最近更新 更多