我正在为我的应用程序进行一些集成测试,并且遇到了这个问题,我看不到如何解决。
我正在使用Spring Boot 2.4.13 + Spring Data Neo4J 6.1.9
仅供参考,我删除了当您通过Spring Initializr创建一个项目的应用程序默认测试,并且在/src/test/Resources下,我有一个.yml文件。命名
程序
@SpringBootTest
public class ClientIT {
@Autowired
private ClientServiceImpl service;
@Autowired
private ClientRepository repository;
@Test
void someTest() {
//Given
//When
//Then
}
}
。
java.lang.IllegalStateException: Failed to load ApplicationContext
应用
Caused by: java.lang.IllegalStateException: The provided database selection provider differs from the ReactiveNeo4jClient's one.
我什至不明白为什么春季试图加载它。我已经在Spring Data Neo4J GitHub存储库中创建了一个问题( https: ///github.com/spring-projects/spring-data-neo4j/issues/2488 ),但他们只能告诉我,如果我不在类司机或不变的类中,则自动包括exectiveneo4jdataaaautoconfiguration,我将自动包括在内有。
在Junit Jupiter方法没有成功之后,我一直在启动应用程序时调试Spring内部内容。
我可以看到的是,在Junit jupiter测试准备/初始化后的某个时候,“ eactiveNoo4jTemplate”被注入DefaultListableBeanFactory的BeanDefinitionNames变量中。
我尝试了许多旨在使用集成测试时要使用的不同注释的组合,但是有一次它可以使用的是,在我明确排除了Reactiveneo4jdataaautoconfiguration class之后,
@EnableAutoConfiguration(exclude=ReactiveNeo4jDataAutoConfiguration.class)
我在某些blogpost中一直看到的是使用@springboottest,我不应该使用@springboottest我担心这种问题,但看来我需要在每次想进行新的IT测试时补充说注释。
我的集成测试基本上包括引导程序 + Web服务器(tomcat)以及嵌入式的neo4j实例,之后,请求检查所有内容的要求。我真的需要担心所有这些只是为了进行这些简单的测试吗?
谢谢
参考文献:
How do I set up a Spring Data Neo4j integration test with JUnit 5 (in Kotlin)?
I'm making some Integration Tests for my app and I'm encountering this problem I can't see how to solve.
I'm using Spring Boot 2.4.13 + Spring Data Neo4J 6.1.9
FYI, I deleted the Application default test that comes bundled when you create a project through Spring Initializr, and under /src/test/resources I have a .yml file named application.yml
My IT class looks like this:
@SpringBootTest
public class ClientIT {
@Autowired
private ClientServiceImpl service;
@Autowired
private ClientRepository repository;
@Test
void someTest() {
//Given
//When
//Then
}
}
But when I run this test I get the following Exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
And this is the cause:
Caused by: java.lang.IllegalStateException: The provided database selection provider differs from the ReactiveNeo4jClient's one.
The thing is I don't use SDN's Reactive features at all in my project. I don't even understand why Spring tries to load it. I've created an Issue under the Spring Data Neo4j GitHub repository (https://github.com/spring-projects/spring-data-neo4j/issues/2488) but they could only tell me that ReactiveNeo4jDataAutoConfiguration gets automatically included if there's a Driver or Flux class in the classpath which I don't have.
I've been debugging the Spring internals while booting up the Application after JUnit Jupiter methods to no success.
What I could see is that at some point after JUnit Jupiter tests preparation/initialization, "reactiveNeo4jTemplate" gets injected into DefaultListableBeanFactory's beanDefinitionNames variable.
I've tried many combinations of different annotations intended to be used when making Integration Tests but the one time it worked was after I explicitly excluded ReactiveNeo4jDataAutoConfiguration class through
@EnableAutoConfiguration(exclude=ReactiveNeo4jDataAutoConfiguration.class)
What I've always seen in some blogposts is that by using @SpringBootTest I shouldn't worry about this kind of problem but it looks like I need to add that annotation every time I want to make a new IT test.
My Integration Tests basically consist of bootstrapping the application + web server (tomcat) along with an embedded Neo4J instance and after that, making requests to check everything works as it should. Do I really need to worry about all of this just to make these simple tests?
Thank you
References:
How do I set up a Spring Data Neo4j integration test with JUnit 5 (in Kotlin)?
SprintBootTest - create only necessary beans
发布评论
评论(1)
在发现是什么原因引起此错误之后回答我自己的问题:
在链接的GitHub问题中,其中一位开发人员说,在classpath sdn中有
flux.class
sdn中实例化neo4JReactiveDataaaautoconoconfiguration
哪个哪个是导致其他反应豆实例化的原因。显然,
neo4j-harness
带来了io.projectReactor
(其中flux.class.class
属于)作为间接依赖性通过neo4j-fabric
代码>这是我们问题的根源。春季数据NEO4J将在本周晚些时候的补丁中解决此问题。
Answering my own question after finding what is causing this error:
In the linked Github Issue, one of the developers says having
Flux.class
in the classpath forces SDN to instantiateNeo4jReactiveDataAutoConfiguration
which is what is causing the other reactive beans to instantiate.Apparently,
neo4j-harness
bringsio.projectreactor
(whereFlux.class
belongs) as an indirect dependency throughneo4j-fabric
which is the root of our problems.The Spring Data Neo4j will be fixing this issue in a patch later this week.