当前位置: 首页 > 知识库问答 >
问题:

从Spring Boot Starter连接到本地neo4j服务器实例

华景明
2023-03-14

我正在尝试从spring boot starter连接到本地安装的Neo4j服务器-

服务器安装默认通过Homebrew。

Gradle构建文件

buildscript {
repositories {
    maven { url "http://repo.spring.io/libs-milestone" }
    mavenLocal()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC5")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-accessing-neo4j-data-rest'
    version = '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.data:spring-data-neo4j:3.0.1.RELEASE")
    compile("org.hibernate:hibernate-validator")
    compile("org.springframework.data:spring-data-rest-webmvc")
    compile("org.springframework.data:spring-data-neo4j-rest:3.0.1.RELEASE") <---ADDED
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

一个pplication.java

package hello;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;

@Configuration
@EnableNeo4jRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application extends Neo4jConfiguration {

    public Application() {
        setBasePackage("hello");
    }

//  @Bean(destroyMethod = "shutdown")
//  public GraphDatabaseService graphDatabaseService() {
//      return new GraphDatabaseFactory().newEmbeddedDatabase("target/hello.db");
//  }

    @Bean
    SpringRestGraphDatabase graphDatabaseService() {
        return new SpringRestGraphDatabase("http://localhost:7474/db/data");
    }   

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

没有做任何其他更改。

实际误差:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.HttpMessageConverters org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.messageConverters; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private final java.util.List org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration.converters; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonHttpMessageConverter' defined in class org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.http.converter.json.MappingJackson2HttpMessageConverter org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.jacksonHttpMessageConverter()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapper' defined in class org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public com.fasterxml.jackson.databind.ObjectMapper org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.objectMapper()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntityJackson2Module' defined in class org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public com.fasterxml.jackson.databind.Module org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.persistentEntityJackson2Module()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.rest.core.mapping.ResourceMappings org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.resourceMappings()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositories' defined in class org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.repository.support.Repositories org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.data.neo4j.config.Neo4jConfiguration.setGraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDataBaseService' defined in class hello.Application: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [org.springframework.data.neo4j.rest.SpringRestGraphDatabase hello.Application.graphDataBaseService()] threw exception; nested exception is java.lang.NoClassDefFoundError: javax/ws/rs/core/Response$StatusType

共有2个答案

澹台季萌
2023-03-14

尝试添加neo4j rest的依赖项:

compile("org.neo4j:neo4j-rest-graphdb:2.0.1")
暨成双
2023-03-14

我也有同样的问题。Jersey似乎是必需的,不作为可传递依赖项包含。

compile('com.sun.jersey:jersey-core:1.18.1')

它是有效的。

 类似资料:
  • 我有一个节点。尝试连接到mongodb的js服务器(使用mongoose): 尽管mongodb已启动并运行,但连接失败。 我得到以下日志: 7月18日星期四13:24:50.124[initandlisten]选项:{dbpath:“/home/pi/mongodb/”} Thu Jul 18 13:24:50.166[initandlisten]正在等待端口27017上的连接 Thu Jul

  • 问题内容: 我是Neo4J的新手,尽管经过数小时的谷歌搜索,但仍找不到问题的答案。 到目前为止,我一直在关注这些教程,现在我对如何/何时使用Neo4j有了基本的了解。现在,我将开始修改hello- world代码,并连接到本地安装在计算机上的Neo4J服务器,可通过http://127.0.0.1:7474进行访问。 原始连接(使用嵌入式数据库): 问题是,是否仍然有必要修改此行以连接到c:\ n

  • 我正在尝试从已部署到Azure应用程序服务的API连接到本地SQL Server。我已建立Azure混合连接以连接本地SQL和Azure。我创建了一个连接字符串,其中包括用户名和密码,作为我在本地服务器中创建的本地登录名的用户名和密码。这允许我连接。 连接字符串: 但是,我想使用windows身份验证连接到服务器。我的系统帐户可以访问服务器,但使用连接字符串作为- 或 它给出的错误为 “登录失败。

  • 我正在运行Docker容器,其中运行一个jar文件。 此jar文件需要访问Elasticsearch以读取数据,并且此Elasticsearch服务安装在本地计算机上(不在Docker容器中) 我需要从Docker容器连接到本地Elasticsearch服务以使其正常工作 我在Dockerfile中写了EXPOSE 9200 9300 service-port,我的Docker run命令如下,

  • 问题内容: 错误2002(HY000):无法通过套接字’/var/run/mysqld/mysqld.sock’(2)连接到本地MySQL服务器 我尝试了在互联网上找到的所有内容,但是无法解决在Ubuntu 11.04上出现的问题。 我尝试了这些事情: 使用手动启动mysqld 使用启动mysqld 检查它是否正在使用并获得结果 在手动创建文件 授予用户权限 试图删除并重新安装,但仍然无法正常工作

  • 问题内容: 环境文件: Routes.php: 我得到的错误: *Connector.php第55行中的 *PDOException : SQLSTATE [HY000] [2002]连接尝试失败,因为一段时间后连接方未正确响应,或者由于连接的主机未能响应,所以建立的连接失败。 我的问题是: 我正在尝试从计算机连接到远程MySQL服务器 而且我不明白为什么它不起作用? 我应该怎么做才能连接? 我想