Why does Neo4j OGM with Spring Boot 2.0.0.M4 apparently require the embedded driver?

自作多情 提交于 2019-12-11 14:26:50

问题


I have been trialling Spring Boot 2 (2.0.0.M4 at this stage) with the latest Spring Data Neo4j (currently 5.0.0.RC3) and can't seem to get it running.

I get the following error:

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

I don't ask for an embedded driver, nor do I want one. I only want to use the bolt driver, which is already a dependency of spring-data-neo4j.

I've published a project to Github that was built using output from Spring Initializr that can be run to expose the error.

For reference, my build.gradle is as follows. Am I mis-configuring my project? Or is there something more serious wrong with the current Spring and Neo4j milestone builds?

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"
}

The rest of the code is available in Github as I mentioned earlier.


回答1:


You don't have the embedded driver dependency anywhere, see

./gradlew dependencies

output and search for neo4j-ogm.*driver - only neo4j-ogm-bolt driver is present. So if you want to use bolt only you have the dependencies set up correctly.

The reason why you see this exception is because you configuration is wrong:

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

This doesn't provide path to configuration file, the default then is impermanent embedded database, which needs the embedded driver - hence the exception.

You have two options

  • pass OGM configuration to 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");
    }
    

    beware that this is OGM only solution and doesn't support yml files.

  • use spring boot auto configuration for SDN - just delete the Neo4jConfiguration class, Spring Boot will detect there is no SessionFactory bean and will configure all required (including transaction manager). Keep your Application class and application.yml as it is.



来源:https://stackoverflow.com/questions/46356002/why-does-neo4j-ogm-with-spring-boot-2-0-0-m4-apparently-require-the-embedded-dri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!