我com.fasterxml.jackson.core:jackson-annotations:2.6.0
在我的 gradle 项目中使用。自从添加com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.0
到我的项目构建文件以来,我在运行我的 gradle 项目时遇到了这个异常。这是我的错误的堆栈跟踪。
引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:构造函数抛出异常;嵌套异常是 java.lang.NoSuchMethodError: com.fasterxml.jackson.annotation.JsonFormat$Value.empty()Lcom/fasterxml/jackson/annotation/JsonFormat$Value; 在 org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ... 117 更多原因:java.lang.NoSuchMethodError:com.fasterxml.jackson.annotation.JsonFormat$Value。empty()Lcom/fasterxml/jackson/annotation/JsonFormat$Value; 在 com.fasterxml.jackson.databind.cfg.MapperConfig.(MapperConfig.java:50) 在 com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:535) 在 com.fasterxml.jackson.databind.ObjectMapper.( ObjectMapper.java:452) 在 org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:553) 在 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.(MappingJackson2HttpMessageConverter.java:57) 在 org. springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.(AllEncompassingFormHttpMessageConverter.java:61) 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.(RequestMappingHandlerAdapter.java:187) 在 sun.reflect。NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor. java:422) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ... 119 更多嵌套在 org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.web 的 bean 时出错。 servlet.mvc.method.annotation.RequestMappingHandlerAdapter':bean 的实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:构造函数抛出异常;嵌套异常是 java.lang.NoSuchMethodError: com.fasterxml.jackson.annotation.JsonFormat$Value.empty()Lcom/fasterxml/jackson/annotation/JsonFormat$Value;: java.lang.NoSuchMethodError: com.fasterxml.jackson.annotation .JsonFormat$Value.empty()Lcom/fasterxml/jackson/annotation/JsonFormat$Value; 在 com.fasterxml.jackson.databind.cfg.MapperConfig.(MapperConfig.java:50) 在 com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:535) 在 com.fasterxml.jackson.databind.ObjectMapper.( ObjectMapper.java:452) 在 org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:553) 在 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.(MappingJackson2HttpMessageConverter.java:57) 在 org. springframework.http。
@JsonFormat
我在我的课上没用过。但我确实有JsonSerializer
和JsonDeserializer
注释使用两个类来序列化和反序列化我ZonedDateTime
在 UTC 中的 Json 和 Json。我是第一次做这个序列化和反序列化,所以请提出任何建议。
这是我的gradle文件代码:
apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'jetty' apply plugin: 'maven' apply plugin: 'war'
ext { springVersion = "4.2.4.RELEASE" springSecurityVersion = "4.0.3.RELEASE" }
repositories { mavenLocal() mavenCentral()
/* maven {
url "http://repo.typesafe.com/typesafe/releases/"
} */ }
configurations.all { exclude group: "commons-logging", module: "commons-logging" exclude group: "log4j", module: "log4j" }
dependencies { compile 'org.slf4j:jcl-over-slf4j:1.7.12' compile 'ch.qos.logback:logback-classic:1.1.3' compile "org.springframework:spring-core:$springVersion" compile "org.springframework:spring-context:$springVersion"
compile ("org.springframework:spring-web:$springVersion"){
exclude group: "com.fasterxml.jackson.core" } compile ("org.springframework:spring-webmvc:$springVersion"){
exclude group: "com.fasterxml.jackson.core" } compile "org.springframework:spring-orm:$springVersion" compile "org.springframework.security:spring-security-web:$springSecurityVersion" compile "org.springframework.security:spring-security-config:$springSecurityVersion"
compile "org.aspectj:aspectjrt:1.7.4"
compile "org.hibernate:hibernate-core:4.3.6.Final" compile "org.hibernate:hibernate-entitymanager:4.3.6.Final" compile "javax.servlet:javax.servlet-api:3.1.0" compile "org.javassist:javassist:3.15.0-GA" compile "mysql:mysql-connector-java:5.1.31"
compile "org.hsqldb:hsqldb:2.3.2"
compile "commons-dbcp:commons-dbcp:1.2.2" compile "org.apache.commons:commons-lang3:3.4" compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.0' compile 'com.fasterxml.jackson.core:jackson-core:2.7.0' compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.7.0'
compile "net.sf.ehcache:ehcache-core:2.6.9" compile "org.hibernate:hibernate-ehcache:4.3.5.Final" compile "com.h2database:h2:1.4.177" compile "com.google.code.gson:gson:2.6.2"
testCompile ("junit:junit:4.12"){
exclude group: "org.hamcrest" } testCompile "org.springframework:spring-test:$springVersion" testCompile "org.easetech:easytest-core:1.4.0" testCompile "org.mockito:mockito-core:1.9.5" testCompile "org.hamcrest:hamcrest-all:1.3" testCompile "com.jayway.jsonpath:json-path:2.2.0" testCompile "com.jayway.jsonpath:json-path-assert:2.2.0"
testRuntime "org.hsqldb:hsqldb:2.3.2" }