且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

测试失败,并带有TransactionRequiredException:同时加载JPA和Neo4J配置时,没有事务正在进行中异常

更新时间:2023-10-09 23:52:34

我可以使用根据尽力而为1PC"实现Spring ChainedTransactionManager.西蒙(Simon)在我只需要更改Neo4j配置.我什至不必触摸其他JPA事务管理器中的任何内容.

I just had to change my Neo4j configuration. I didn't even have to touch anything in the other JPA transaction manager.

这是我的Neo4j配置:

Here is my Neo4j configuration:

@EnableNeo4jRepositories(basePackages = { "it.robot.data.neo4j.repository" })
@EnableTransactionManagement
@ComponentScan(basePackages = { "it.robot.data.neo4j.service" })
public class Neo4JRepositoryConfiguration extends Neo4jConfiguration {

  private static Logger logger = LoggerFactory.getLogger(Neo4JRepositoryConfiguration.class);

  public static final String URL = "http://localhost:7474/db/data/";
  public static final String LOGIN = "neo4j";
  public static final String PASSWORD = "xxxxx";

  Neo4JRepositoryConfiguration() {
    setBasePackage("it.robot.data.neo4j.domain");
  }

  @Bean
  GraphDatabaseService graphDatabaseService() {
    return new SpringCypherRestGraphDatabase(URL, LOGIN, PASSWORD);
  }

  @Autowired
  LocalContainerEntityManagerFactoryBean entityManagerFactory;

  @Override
  public PlatformTransactionManager neo4jTransactionManager(
      GraphDatabaseService graphDatabaseService) {
    return new ChainedTransactionManager(
        new JpaTransactionManager(entityManagerFactory.getObject()),
        new JtaTransactionManagerFactoryBean(graphDatabaseService).getObject());
  }

}