feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter found

出错的代码:

  UserBaseDto lmsInfo = userBaseClient.getUserById(pointMqVo.getUserId(), pointMqVo.getPlatformId());

调用的代码:

    @ApiOperation(httpMethod = "GET", value = "根据用户Id查询用户信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String",required = true, paramType = "query"),
            @ApiImplicitParam(name = "platformId", value = "平台id", dataType = "String", paramType = "query"),
    })
    @RequestMapping("/getUserById")
    public UserBaseDto getUserById(@RequestParam String userId,@RequestParam(required = false) String platformId) {
        UserBaseInfo data = userBaseService.findById(userId, platformId);
        return UserBaseInfo.infoToDto(data);
    }

报错的信息:

feign.codec.DecodeException: Could not extract response:
 no suitable HttpMessageConverter found for response type [class 
com.chinahrt.gp6.system.sharevo.UserBaseDto] 
and content type [text/html;charset=utf-8]

问题分析:

断点调试时,不走被调用方法上打的断点,我一直怀疑是远程调用不通导致的。

看报错信息,又百度以为是feign调用不支持UserBaseDto这种返回类型,就用了一个返回String类型的方法进行调用测试,当时报SQL错误。突然意识到其实他走被调用方法的查询,并且查询的sql有错,无法返回这个错误信息导致的报上面错误。并不是无法返回UserBaseDto。 

而SQL报错这么简单的问题,我为什么没有发现是因为写测试用例,一般是看这里,这里提示feign.codec.DecodeException: ...,而前面那个Run那里提示SQL运行错误。

sql报错信息如下:

{"code":"UNKNOWN_EXCEPTION","message":"\r\n### Error querying database.  
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 
'platform_id' in 'where clause'\r\n### The error may exist in file
 [E:\\liziyi\\xxx\\xxx-system\\target\\classes\\mapper\\UserBaseDao.xml]\r\n### 
The error may involve defaultParameterMap\r\n### The error occurred while setting 
parameters\r\n### SQL: select 
id,name,password,parent_id,idcard,picture,real_name,sex,birthday,mobile,email,
create_time,seal_flag,if_open,weixin_opernid,if_vip,nick_name,thirdparty_id,
thirdparty,user_level,nation,last_login_time,last_login_source,if_test,if_provider,
account_money,last_modify_time,last_pwd_modify_time,if_student,if_manager,
department,position,polevel_id,base_id,political_id,degree_id,prof_id,office_phone,
if_enable_update,if_check,jobtitle_id,obtitle_date,units_natureid,units_fieldid,
office_address,administration_position,domiciliary_register,college,specialty,
degree_no,birth_place,applicants_rating,address,political_title,if_transform,
transform_time,units_industry,bind_id,bind_name,bind_role,bind_plan,info_from,
interest,personal_summary,professional_technical,professional_title,level_name,
work_area,function_level,identity_id,administrative_range,qq,office_nature,my_point,
my_get_point,my_exchange_point,certificate_title_series,certificate_right_name,
certificate_profession_name,bind_user_id,manage_unit,general1,general2,general3,
general4,general5,train_no,train_address,home_address,domiciliary_type,train_type,
train_work_area,train_level,ssn,professional_value from user_base where id=?     
      AND platform_id = ?\r\n### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
 'platform_id' in 'where clause'\n; bad SQL grammar []; nested exception is 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
 'platform_id' in 'where clause'|请求地
址:http://xxx/xxx/system/serviceApi/user/getUserById,参
数:userId=111111&platformId=1,traceId="}

解决办法:

现在定位出来,是因为sql的问题,不是服务间调用不同,也不是无法传UserBaseDto这个参,而是SQL报错。把SQL报错的地方修改完成即可。上面SQL报错信息意思是platform_id元素有问题,因为我的表中没有这个元素,我传了这个参数,所以报错。

希望大家准确的定位自己的问题。

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/122586551