【发布时间】: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