2015-11-09 36 views
2

问题

Spring Data REST Reference Documentation弹簧数据休息-HAL-浏览器集成表示,春数据休息和使用Spring引导

dependencies { 
    compile 'org.springframework.data:spring-data-rest-hal-browser' 
} 

足以HAL浏览器与Spring数据休息集成,并使用Spring启动但Gradle抱怨说,除非我指定特定版本,否则无法找到这种依赖关系,所以我通过指定the latest one available in central repository(存储库中没有其他可用版本)来修复它。指定版本后的依赖性被解析,但我春天靴子收纳在初始化过程中出现错误:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object; 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    ... 151 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object; 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:966) 
    at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:95) 
    at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:88) 
    at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:81) 
    at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:182) 
    at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.CGLIB$repositories$11(<generated>) 
    at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0$$FastClassBySpringCGLIB$$ec6a4119.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.repositories(<generated>) 
    at sun.reflect.NativeMetssorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 152 more 
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object; 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) 
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) 
    ... 173 more 

但是我的应用程序成功启动并如预期工作,如果我删除spring-data-rest-hal-browser:2.4.0.RELEASE依赖。

问题

如何设置我的build.gradle正确我的申请与HAL浏览器正确地集成?


build.gradle

buildscript { 
    ext { 
     springBootVersion = '1.2.7.RELEASE' 
    } 

    repositories { 
     mavenCentral() 
    } 
} 

dependencies { 
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE') 
} 

[...] 

repositories { 
    mavenCentral() 
    flatDir { 
     dirs 'lib' 
    } 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-data-rest') 
    compile('org.springframework.boot:spring-boot-starter-remote-shell') 
    compile('org.springframework.data:spring-data-rest-hal-browser:2.4.0.RELEASE') 
    compile('org.projectlombok:lombok:1.16.6') 
    compile name: 'ojdbc6' 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('org.springframework.restdocs:spring-restdocs-mockmvc:1.0.0.RELEASE') 
} 
+0

你确定,你提供了一个正确的脚本?据它,你有buildscript配置封闭内的所有配置,但一些配置必须在脚本的根。 – Stanislav

+0

是的,你是对的。我弄乱了一些花括号和缩进。我已经纠正它。 –

回答

1

的自动版本管理的HAL浏览器只能先从春天引导1.3.0是在发布候选阶段,应该很快被释放。候选发布对我来说是非常稳定的,所以你可以考虑给一个尝试通过您的构建更新到1.3.0.RC1我期望会解决这个问题,这样的事情:

buildscript { 
    ext { 
     springBootVersion = '1.3.0.RC1' 
    } 
    repositories { 
     mavenCentral() 
     maven { url 'https://repo.spring.io/milestone/' } 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
     classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE" 
    } 
} 

repositories { 
    mavenCentral() 
    flatDir { 
     dirs 'lib' 
    } 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-data-rest') 
    compile('org.springframework.boot:spring-boot-starter-remote-shell') 
    compile('org.springframework.data:spring-data-rest-hal-browser') 
    compile('org.projectlombok:lombok:1.16.6') 
    compile name: 'ojdbc6' 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('org.springframework.restdocs:spring-restdocs-mockmvc') 
} 

你可以看到托管依赖版本1.3.0.RC1这里:

http://docs.spring.io/spring-boot/docs/1.3.0.RC1/reference/htmlsingle/#appendix-dependency-versions

,如果你看一下管理依赖版本1.2.7,无论是spring-data-rest-hal-browser也不spring-restdocs-mockmvc存在你会发现。