java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType

4 篇文章 1 订阅
本文介绍了一种常见的Java运行时异常NoSuchMethodError及其解决方案。该异常通常发生在使用Spring框架结合Jackson进行JSON序列化操作时,当项目的类路径中缺少必要的Jackson模块依赖时出现。文章详细分析了异常产生的原因,并提供了一个具体的例子来说明如何通过添加正确的Maven依赖来解决这个问题。
摘要由CSDN通过智能技术生成
 java.lang.NoSuchMethodError:  com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;] with root cause
java.lang.NoSuchMethodError:  com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
       at  org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:264)
       at  org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100)
       at  org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:225)
       at  org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:173)
       at  org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
       at  org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:130)
       at  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
       at  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
       at  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
       at  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
       at  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
       at  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
       at  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
       at  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
       at  org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
       at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at  org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at  org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
       at  org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
       at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at  org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at  org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
       at  org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
       at  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
       at  org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
       at  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
       at  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
       at  org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
       at  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
       at  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
       at  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
       at  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
       at  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at java.lang.Thread.run(Thread.java:748)

 

缺失jackson-module-jaxb-annotation依赖,参考如下

 <dependency>

       <groupId>com.fasterxml.jackson.module</groupId>

       <artifactId>jackson-module-jaxb-annotations</artifactId>

       <version>${jackson.version}</version>

 </dependency>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值