问题
我正在使用Neo4j数据库构建一个应用程序。我想使用Spring Boot的@DataNeo4jTest
注释(参见Spring Boot Test - Neo4j)来测试一些自定义Cypher查询,但是我遇到了以下问题之一:
- 测试尝试使用BOLT驱动程序连接到Neo4j实例。
- 测试无法加载嵌入式驱动程序。
细节
我的依赖项通过Maven进行管理,遵循Spring Data Neo4j参考文档。 SDN文档的第10.3.1节解释如下:
默认情况下,SDN将使用BOLT驱动程序连接到Neo4j,您不需要在pom中声明它作为单独的依赖项。如果您想在生产应用程序中使用嵌入式或HTTP驱动程序,则必须添加以下依赖项。(如果您只想在测试中使用嵌入式驱动程序,则不需要此嵌入式驱动程序的依赖项。有关详细信息,请参见下面的测试部分)。
因此,我pom.xml
的相关部分如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi=...>
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
...
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
我的main/resources/application.yml
文件内容如下:
spring:
data:
neo4j:
uri: bolt://localhost
username: <username>
password: <password>
我的test/resources/application.yml
文件内容如下:
spring.data.neo4j.uri: file:///neo4j.db
如果没有test/resources/application.yml
,我会得到以下异常,我认为这是使用BOLT驱动程序导致的:
org.springframework.transaction.CannotCreateTransactionException: Could not open Neo4j Session for transaction;
nested exception is org.neo4j.driver.v1.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
使用 test/resources/application.yml
文件时,我遇到了以下异常:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'neo4jAuditionBeanFactoryPostProcessor': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception;
nested exception is org.neo4j.ogm.exception.core.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
问题
- 是否缺少任何依赖项?
- 配置是否有误?
- 是否有人有一个使用Spring Boot注释
@DataNeo4jTest
的工作示例链接?
欢迎提出任何建议。