Spring数据Mongo DB错误的REST配置

时间:2016-08-27 21:53:20

标签: java spring mongodb rest spring-mvc

目前我正在使用Spring和Mongo DB编写一些小型Web应用程序。我的问题是在REST中显示ID。我找到了这个解决方案:

import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;

import pl.rakoczy.taskmanager.model.Task;

@Configuration
public class RepositoryConfig extends
        RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(
            RepositoryRestConfiguration config) {
        config.exposeIdsFor(Task.class);
    }
}

启动应用程序异常后出现:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryExporterHandlerAdapter' defined in class path resource [pl/rakoczy/taskmanager/repository/RepositoryConfig.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation;

我找到了更新gradle配置中某些依赖项的解决方案,但我认为我确实有最新版本:

dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'

compile group: 'org.springframework', name: 'spring-context', version: '4.3.2.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '4.3.2.RELEASE'
compile group: 'org.springframework', name: 'spring-beans', version: '4.3.2.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '4.3.2.RELEASE'
compile group: 'org.springframework', name: 'spring-expression', version: '4.3.2.RELEASE'
compile group: 'org.springframework', name: 'spring-asm', version: '3.1.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.4.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.0.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '1.9.2.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.10.2.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-rest-webmvc', version: '2.0.0.RELEASE'
compile group: 'org.springframework.hateoas', name: 'spring-hateoas', version: '0.16.0.RELEASE'

compile group: 'org.tinylog', name: 'tinylog', version: '1.1'

compile group: 'javax.inject', name: 'javax.inject', version: '1'

compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.3.0'

compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.9'

compile group: 'cglib', name: 'cglib-nodep', version: '3.2.4'

testCompile 'junit:junit:4.12'
testCompile 'com.jayway.jsonpath:json-path'
testCompile 'org.springframework.boot:spring-boot-starter-test'

}

我是春天新手,你能看到任何问题吗?

2 个答案:

答案 0 :(得分:0)

错误说Spring正在尝试在该类中调用init()方法,并且不存在。

请参阅弹簧文档:http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.adding-sdr-to-spring-mvc-app

答案 1 :(得分:0)

您已添加Spring和Spring启动依赖项。最好的方法是使用Spring Boot依赖项,然后根据需要添加其他依赖项。请检查https://spring.io/guides/gs/accessing-data-mongodb/。您获得的错误与“org.springframework.data.util.ClassTypeInformation”类有关,该类是spring-data-commons jar文件的一部分。检查部署的war文件中是否存在此jar文件及其最新版本。我将再次建议您清理Gradle构建并保留必需和最新文件。例如,您使用的是旧版本的spring-data-rest-webmvc。