且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Spring restTemplate中找不到HttpMessageConverter

更新时间:2023-11-22 11:53:40

我发现,可能导致此问题的原因有-

Couple of reasons, I found, that can cause this issue are -

  1. setters/getters的数据类型与实际属性的数据类型不同(在sunghun的评论中也提到过)
  2. 如果有重载的方法看起来像字段的setter/getter,则与setField或getField相同,其中field是类的属性.

我有一个字段private boolean success和2个设置方法-

I had a field private boolean success and 2 setter methods -

public void setSuccess(List<Object> dataList);
public void setSuccess(boolean success);

在调试时,我发现类com.fasterxml.jackson.databind.deser.BeanDeserializerFactory引发异常.此异常在Jackson的lib中被抑制,RestTemplate抛出的异常与主题相同.

On debugging, I found that class com.fasterxml.jackson.databind.deser.BeanDeserializerFactory was throwing an exception. This exception was suppressed within Jackson's lib and the exception thrown by the RestTemplate was the same as the subject.

java.lang.IllegalArgumentException: Conflicting setter definitions for property "failure": com.test.dto.JsonResponse#setFailure(1 params) vs com.test.dto.JsonResponse#setFailure(1 params)

我将方法更改为public void setSuccessData(List<Object> dataList);,并且效果很好.

I changed the method to public void setSuccessData(List<Object> dataList); and it worked fine.

希望这对某人有帮助.