从Spring Boot Starter连接到本地neo4j Server实例

时间:2014-03-30 21:59:39

标签: spring neo4j spring-data spring-data-neo4j spring-data-rest

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

服务器安装默认为Homebrew。

Gradle Build File

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

Application.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 个答案:

答案 0 :(得分:1)

尝试添加neo4j rest的依赖项:

compile("org.neo4j:neo4j-rest-graphdb:2.0.1")

答案 1 :(得分:1)

我有同样的问题。看来泽西岛是必需的,不包括在传递依赖中。

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

它有效。