欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

feign.codec.DecodeException:Couldnotextractresponse:nosuitableHttpMessageConverterfound

时间:2023-08-03
出错的代码:

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":"rn### Error querying database、 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'platform_id' in 'where clause'rn### The error may exist in file [E:\liziyi\xxx\xxx-system\target\classes\mapper\UserbaseDao.xml]rn### The error may involve defaultParameterMaprn### The error occurred while setting parametersrn### 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 = ?rn### 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元素有问题,因为我的表中没有这个元素,我传了这个参数,所以报错。

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

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。