【问题标题】:How can I use the Bolt driver with Spring Boot/Data Neo4j如何在 Spring Boot/Data Neo4j 中使用 Bolt 驱动程序
【发布时间】:2016-12-26 02:29:57
【问题描述】:

我从 Spring Boot 收到此错误。

Could not deduce driver to use based on URI 'bolt://localhost:7687

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

spring.data.neo4j.uri=bolt://localhost:7687

我确实添加了驱动程序

   <dependency>
        <scope>runtime</scope>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-bolt-driver</artifactId>
        <version>${neo4j-ogm.version}</version>
    </dependency>

imagine spring boot doesn't support autoconfiguration for this yet

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

【问题讨论】:

标签: java spring-boot neo4j spring-data spring-data-neo4j-4


【解决方案1】:

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

这应该足以让你继续前进:

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

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

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

【讨论】:

    【解决方案2】:

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

    在这种情况下,我得到了“未知协议:螺栓”。

    问题是DriverConfiguration.setURI() 将尝试实例化java.net.URL 以检索userNamepassword 并设置驱动程序。我认为最好使用java.net.URI,因为我们不需要打开连接,只需要获取信息。

    查看这篇文章: why does java's URL class not recognize certain protocols?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      相关资源
      最近更新 更多