Rollback Spring数据Neo4j-单元测试-事务回滚但未删除数据

Rollback Spring数据Neo4j-单元测试-事务回滚但未删除数据,rollback,spring-data-neo4j,spring-transactions,spring-test,Rollback,Spring Data Neo4j,Spring Transactions,Spring Test,我正在使用spring boot(1.1.8.RELEASE)、spring-data-neo4j(3.2.0.RELEASE)构建一个应用程序,以便通过RESTAPI连接到独立的neo4j服务器。我使用SpringTest来测试应用程序,我已经实现了一个单元测试来创建一个节点并检索它它工作正常,但测试完成后新节点仍保留在数据库中,但是我希望回滚事务并删除节点 但是,在控制台中,我可以看到以下语句 "Rolled back transaction after test execution for

我正在使用spring boot(1.1.8.RELEASE)、spring-data-neo4j(3.2.0.RELEASE)构建一个应用程序,以便通过RESTAPI连接到独立的neo4j服务器。我使用SpringTest来测试应用程序,我已经实现了一个单元测试来创建一个节点并检索它它工作正常,但测试完成后新节点仍保留在数据库中,但是我希望回滚事务并删除节点

但是,在控制台中,我可以看到以下语句

"Rolled back transaction after test execution for test context...
**我不明白为什么在控制台上似乎发生了回滚,但事务已提交到数据库**

如果有人能帮我找出问题的根源,我将不胜感激

下面是我的spring配置

@Configuration
@ComponentScan
@EnableTransactionManagement
@EnableAutoConfiguration
public class AppConfig extends Neo4jConfiguration {

public AppConfig() {
    setBasePackage("demo");
}

@Bean
public GraphDatabaseService graphDatabaseService(Environment environment) {
    return new SpringRestGraphDatabase("http://localhost:7474/db/data");
}

}
找到下面我的测试类

@SuppressWarnings("deprecation")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AppConfig.class)
@Transactional
public class AppTests {

@Autowired
private Neo4jTemplate template;

@Test
public void templateTest() {

    Person person = new Person();
    person.setName("Benoit");
    person.setBorn(1986);

    Person newPerson = template.save(person);

    Person retrievedPerson = template.findOne(newPerson.getNodeId(),Person.class);

    Assert.assertEquals("Benoit", retrievedPerson.getName());
}

}
我试图在我的单元测试类中添加以下注释,但它没有改变任何内容:

@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
根据我在其他帖子中看到的内容,我还尝试在单元测试中添加以下内容

implements ApplicationContextAware
谢谢你的帮助


考虑到您正在经历的行为是意料之中的:SpringTestContext框架(TCF)中的事务支持在这方面没有任何问题

TCF通过配置的
transactionManager
管理事务

因此,当您切换到一个嵌入式数据库并使用该嵌入式数据库的数据源配置事务管理器时,这一点非常有效。问题在于Neo4J REST中的事务支持与Spring的事务管理功能不匹配。正如michaelhunger在您引用的另一个线程中所述,neo4jrestapi的新版本应该解决这个问题

请注意,使用
@TransactionConfiguration
注释您的测试类没有任何效果,因为您只是用默认值覆盖默认值,而默认值没有任何效果。此外,在测试类中实现
ApplicationContextAware
对事务管理没有影响

问候,


Sam(
spring test
component lead)

FYI我用嵌入式数据库尝试了相同的方案,效果很好。我想知道独立neo4j服务器的spring-data-neo4j事务支持是否存在问题。基于下面的帖子[链接],框架的下一个版本(3.3.0)将利用新的neo4j rest事务端点,我希望它会有所不同。让我知道我是否在正确的轨道上?