如下,引入FastJsonHttpMessageConverter 之后,导致了新的错误:
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
/**
* 1.需要定义一个convert转换消息的对象
* 2.创建配置信息,加入配置信息:比如是否需要格式化返回的json
* 3.converter中添加配置信息
* 4.convert添加到converters当中
*/
FastJsonHttpMessageConverter fastJsonHttpMessageConverter =
new FastJsonHttpMessageConverter();
// FastJsonConfig fastJsonConfig = new FastJsonConfig();
// fastJsonConfig.setSerializerFeatures(
// SerializerFeature.PrettyFormat
// );
FastJsonConfig fjc = new FastJsonConfig();
fjc.setDateFormat("yyyy-MM-dd");
fastJsonHttpMessageConverter.setFastJsonConfig(fjc);
converters.add(fastJsonHttpMessageConverter);
}
错误如下:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.AbstractMethodError
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:) [spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:) [spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:) [spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:) [tomcat-embed-websocket-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at ch.qos.logback.access.servlet.TeeFilter.doFilter(TeeFilter.java:) [logback-access-1.2..jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:) [druid-1.0..jar:1.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:) [spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:) [spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:) [tomcat-embed-core-9.0..jar:9.0.]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:) [na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:) [na:1.8.0_201]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:) [tomcat-embed-core-9.0..jar:9.0.]
at java.lang.Thread.run(Thread.java:) [na:1.8.0_201]
Caused by: java.lang.AbstractMethodError: null
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
... common frames omitted
其实关键的错误原因在最后面, 好像是writeWithMessageConverters的原因, 可是不知道具体怎么回事, 搜索writeWithMessageConverters 无果,搜索 fastjson writeWithMessageConverters AbstractMethodError 无果,官方搜索issue ,原来是 fastjson 版本问题 !
升级到 1.2.58 , 解决!
总结:
一看到AbstractMethodError , 就应该想到可能是版本兼容的问题。因为版本的升级,通常会发生api的改变,从容导致原来好好的接口现在就不可以直接用了。。