为什么带有Spring Boot 2.0.0.M4的Neo4j OGM显然需要嵌入式驱动程序? [英] Why does Neo4j OGM with Spring Boot 2.0.0.M4 apparently require the embedded driver?

查看:480
本文介绍了为什么带有Spring Boot 2.0.0.M4的Neo4j OGM显然需要嵌入式驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我收到以下错误:

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

我既不需要嵌入式驱动程序,也不需要.我只想使用螺栓驱动程序,该驱动程序已经是spring-data-neo4j的依赖项.

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.

我已经发布了一个使用输出构建的 Github项目 Spring Initializr 可以运行以暴露错误.

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

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

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

如我之前提到的,其余代码可在Github中找到.

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

推荐答案

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

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

./gradlew dependencies

输出并搜索neo4j-ogm.*driver-仅存在neo4j-ogm-bolt驱动程序.因此,如果只想使用bolt,则可以正确设置依赖项.

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.

您有两个选择

  • 将OGM配置传递给SessionFactory:

  • 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");
}

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

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

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

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.

这篇关于为什么带有Spring Boot 2.0.0.M4的Neo4j OGM显然需要嵌入式驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆