如何在Spring Boot/Data Neo4j中使用Bolt驱动程序

xen*_*ide 2 java neo4j spring-data spring-boot spring-data-neo4j-4

我从Spring Boot得到这个错误.

Could not deduce driver to use based on URI 'bolt://localhost:7687
Run Code Online (Sandbox Code Playgroud)

尝试使用属性或env变量进行配置时

spring.data.neo4j.uri=bolt://localhost:7687
Run Code Online (Sandbox Code Playgroud)

我添加了驱动程序

   <dependency>
        <scope>runtime</scope>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-bolt-driver</artifactId>
        <version>${neo4j-ogm.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我认为spring boot不支持自动配置

如何手动设置此驱动程序以使用Spring Boot/Data?请举个例子.

Vin*_*nce 5

目前用于Neo4j的Spring Boot启动器未检测到bolt协议,因此无法自动配置Bolt驱动程序.但是,如果在应用程序上下文中提供配置Bean,Spring Boot将使用它,而不是尝试自动配置驱动程序本身.

这应该足以让你前进:

@Bean
public Configuration getConfiguration() {
   Configuration config = new Configuration();
   config
       .driverConfiguration()
       .setURI("bolt://localhost");
   return config;
}
Run Code Online (Sandbox Code Playgroud)

请注意,您不需要在配置中声明驱动程序名称,它将从URI中自动检测.

另外,请注意Configuration该类实际上org.neo4j.ogm.config.Configuration,您可能需要明确使用它.

  • 对于未来的读者,属性适用于引导1.4.1 (2认同)