Java NoClassDefFoundError:Spring/REST教程中的MappingJackson2HttpMessageConverter
我正在尝试离线构建和运行本教程“使用Spring设计和实现RESTfulWeb服务”,使用本地存储库存储我的依赖项。这是我的gradle.build文件:Java NoClassDefFoundError:Spring/REST教程中的MappingJackson2HttpMessageConverter,java,spring,rest,spring-mvc,Java,Spring,Rest,Spring Mvc,我正在尝试离线构建和运行本教程“使用Spring设计和实现RESTfulWeb服务”,使用本地存储库存储我的依赖项。这是我的gradle.build文件: apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' repositories { flatDir { dirs 'lib' } } dependencies { compile 'org.springframework:spring-core:4.0.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
repositories {
flatDir { dirs 'lib' }
}
dependencies {
compile 'org.springframework:spring-core:4.0.6.RELEASE'
compile 'org.springframework:spring-beans:4.0.6.RELEASE'
compile 'org.springframework:spring-context:4.0.6.RELEASE'
compile 'org.springframework:spring-web:4.0.6.RELEASE'
compile 'org.springframework:spring-webmvc:4.0.6.RELEASE'
compile 'com.jayway.jsonpath:json-path:0.8.1'
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-jdk14:1.7.5'
// {!begin jackson}
runtime 'com.fasterxml.jackson.core:jackson-core:2.4.2'
runtime 'com.fasterxml.jackson.databind:jackson-databind:2.4.2'
runtime 'com.fasterxml.jackson.annotation:jackson-annotations:2.4.2'
// {!end jackson}
// {!begin jaxb}
runtime 'javax.xml.bind:jaxb-api:2.2.9'
// {!end jaxb}
// {!begin commons}
runtime 'org.apache.commons:commons-logging:1.1.1'
// {!end commons}
testCompile 'org.springframework:spring-test:4.0.6.RELEASE'
testCompile 'junit:junit:4.+'
testCompile "org.mockito:mockito-all:1.9.5"
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile 'javax.servlet:javax.servlet-api:3.0.1'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}
某些测试失败,出现以下错误:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
此类位于spring-web-4.0.6.RELEASE.jar中,它位于依赖项中。我缺少什么?
NoClassDefFoundError
表示该类在编译时位于类路径上,但在运行时丢失。检查您的运行时类路径。请添加整个stacktrace。我不确定,但我认为缺少一个类,MappingJackson2HttpMessageConverter
需要这个类。这个错误意味着JVM已经尝试加载所提到的类,但失败了。如果重新运行测试,您看到的第一条提到该类的异常消息是什么?