当前位置:   article > 正文

Spring Cloud Fegin 接口调用之类型转换异常处理_feign.codec.decodeexception

feign.codec.decodeexception

1. 调用方异常信息

feign.codec.DecodeException: 内部错误,请稍后再试
	at feign.InvocationContext.proceed(InvocationContext.java:40)
	at feign.AsyncResponseHandler.decode(AsyncResponseHandler.java:116)
	at feign.AsyncResponseHandler.handleResponse(AsyncResponseHandler.java:89)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:141)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:91)
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2. 被调用方异常信息

Failed to convert value of type ‘java.lang.String’ to required type

org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.*.Xxx'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.*.Xxx': no matching editors or conversion strategy found
	at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:129)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146)
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注1:目标类型 ‘com.*.Xxx’ 做了脱敏处理

3. 解决方案:增加类型转换器

@Configuration
public class StringToObjectConfiguration implements WebMvcConfigurer {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new JSONStringToObjectParamConverter());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/813894
推荐阅读
相关标签
  

闽ICP备14008679号