1

我正在尝试从 Spring Boot 启动器连接到本地安装的 Neo4j 服务器-> gs-accessing-neo4j-data-rest http://spring.io/guides/gs/accessing-neo4j-data-rest/

服务器安装是默认通过 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'
}

应用程序.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
4

2 回答 2

1

尝试添加 neo4j 的依赖项:

compile("org.neo4j:neo4j-rest-graphdb:2.0.1")
于 2014-04-06T13:23:25.710 回答
1

我遇到过同样的问题。看来 Jersey 是必需的,并且不包含在传递依赖项中。

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

它有效。

于 2014-06-21T02:35:30.517 回答