【问题标题】:Spring data Mongo DB wrong REST configurationSpring数据Mongo DB错误的REST配置
【发布时间】:2016-08-27 21:53:19
【问题描述】:

目前我正在使用 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'

}

我是 Spring 的新手,你能看出什么问题吗?

【问题讨论】:

    标签: java spring mongodb rest spring-mvc


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      错误表明 Spring 正在尝试调用该类中的 init() 方法,但不存在。

      在此处查阅 spring 文档:http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.adding-sdr-to-spring-mvc-app

      【讨论】:

        猜你喜欢
        • 2019-01-06
        • 2016-04-17
        • 1970-01-01
        • 1970-01-01
        • 2017-10-30
        • 2012-09-23
        • 2013-04-30
        • 1970-01-01
        相关资源
        最近更新 更多