【问题标题】:Why does Neo4j OGM with Spring Boot 2.0.0.M4 apparently require the embedded driver?为什么带有 Spring Boot 2.0.0.M4 的 Neo4j OGM 显然需要嵌入式驱动程序?
【发布时间】:2018-03-03 12:26:58
【问题描述】:

我一直在使用最新的 Spring Data Neo4j(当前为 5.0.0.RC3)试用 Spring Boot 2(现阶段为 2.0.0.M4),但似乎无法运行。

我收到以下错误:

org.neo4j.ogm.exception.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver

我不要求嵌入式驱动程序,也不想要一个。我只想用bolt driver,它已经是spring-data-neo4j的依赖了。

我已经发布了一个 project to Github,它是使用来自 Spring Initializr 的输出构建的,可以运行它来暴露错误。

供参考,我的build.gradle如下。我是否错误地配置了我的项目?还是当前的 Spring 和 Neo4j 里程碑版本存在更严重的问题?

buildscript {
    ext {
        springBootVersion = '2.0.0.M4'
    }
    repositories {
        mavenCentral()
        maven { url 'https://repo.spring.io/snapshot' }
        maven { url 'https://repo.spring.io/milestone' }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

version = "0.0.1-SNAPSHOT"

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}

dependencies {
    compile "org.apache.tomcat.embed:tomcat-embed-jasper"
    compile "org.springframework.boot:spring-boot-starter-web"
    compile "org.springframework.boot:spring-boot-starter-data-neo4j"
    runtime "org.springframework.boot:spring-boot-devtools"
}

如前所述,其余代码在 Github 中可用。

【问题讨论】:

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


    【解决方案1】:

    您在任何地方都没有嵌入式驱动程序依赖项,请参阅

    ./gradlew dependencies
    

    输出并搜索 neo4j-ogm.*driver - 只有 neo4j-ogm-bolt 驱动程序存在。因此,如果您只想使用 Bolt,则必须正确设置依赖项。

    你看到这个异常的原因是你配置错误:

    return new SessionFactory("com.example.domain");
    

    这不提供配置文件的路径,默认是无常嵌入式数据库,它需要嵌入式驱动程序 - 因此例外。

    你有两个选择

    • 将 OGM 配置传递给 SessionFactory:

      @Bean
      public org.neo4j.ogm.config.Configuration configuration() {
          return new org.neo4j.ogm.config.Configuration.Builder(new ClasspathConfigurationSource("ogm.properties")).build();
      }
      @Bean
      public SessionFactory sessionFactory() {
          return new SessionFactory(configuration(), "com.example.domain");
      }
      

      请注意,这只是 OGM 解决方案,不支持 yml 文件。

    • 为 SDN 使用 Spring Boot 自动配置 - 只需删除 Neo4jConfiguration 类,Spring Boot 将检测到没有 SessionFactory bean 并将配置所有必需的(包括事务管理器)。保持 Application 类和 application.yml 不变。

    【讨论】:

    • 啊,是的,第二个选项是我的首选,谢谢,我会试试这个。
    • 谢谢您,这清楚地纠正了问题,并且是对 RTFM 更加小心的一个很好的提醒。
    猜你喜欢
    • 2018-03-16
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 2016-12-09
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多