【发布时间】:2018-09-13 09:32:01
【问题描述】:
问题
我使用 Neo4j 数据库构建了一个应用程序。我喜欢使用 Spring Boot 的 @DataNeo4jTest 注释(另见 Spring Boot Test - Neo4j)测试一些自定义 Cypher 查询,但我遇到了以下任一问题:
- 测试尝试使用 BOLT 驱动程序连接到 Neo4j 实例。
- 测试未能加载嵌入式驱动程序。
详情
我的依赖项在Spring Data Neo4j Reference Documentation 之后使用 Maven 进行管理。 SDN 文档的第 10.3.1 节说明:
默认情况下,SDN 将使用 BOLT 驱动程序连接到 Neo4j,您无需在 pom.xml 中将其声明为单独的依赖项。如果要在生产应用程序中使用嵌入式或 HTTP 驱动程序,还必须添加以下依赖项。 (如果您只想使用嵌入式驱动程序进行测试,则不需要对嵌入式驱动程序的依赖。有关详细信息,请参阅下面的Testing 部分)。
因此,我的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的工作示例的链接?
欢迎提出任何建议。
【问题讨论】:
标签: maven spring-boot neo4j spring-data spring-boot-test