• SpringCloud Feign报错:java.lang.IllegalStateException: Method has too many Body parameters


    目录

    1、报错信息

    2、feign多参数问题

    1.1 POST方式

    1.2 GET方式


    1、报错信息

    错误日志内容为:

    Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.soft.framework.core.response.CommResponse com.soft.back.openplatform.api.AdvertApi.insertAdvertTactics(com.soft.back.openplatform.model.AdvertTactics,java.lang.String)
    	at feign.Util.checkState(Util.java:127)
    	at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:117)
    	at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:188)
    	at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:66)
    	at feign.hystrix.HystrixDelegatingContract.parseAndValidatateMetadata(HystrixDelegatingContract.java:46)
    	at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154)
    	at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52)
    	at feign.hystrix.HystrixFeign$Builder.target(HystrixFeign.java:70)
    	at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallbackFactory(HystrixTargeter.java:64)
    	at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:51)
    	at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238)
    	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267)
    	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247)
    	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)
    	... 43 common frames omitted

    2、feign多参数问题

    1.1 POST方式

    错误写法

    public int save(@RequestBody Person p, @RequestBody UserModel user);
    @ApiOperation("保存策略型号关系")
    @PostMapping("/openapi/tactics/insertTacticsModel")
    public CommResponse<?> insertTacticsModel(@RequestBody TacticsModel tm, @RequestBody("tacticsId") Integer tacticsId){}

    feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody。

    正确写法

    @ApiOperation("保存策略型号关系")
    @PostMapping("/openapi/tactics/insertTacticsModel")
    public CommResponse<?> insertTacticsModel(@RequestBody TacticsModel tm, @RequestParam("tacticsId") Integer tacticsId, @RequestParam("modelIds") String modelIds){}


    1.2 GET方式

    错误写法

    @RequestMapping(value="/test", method=RequestMethod.GET)  
    public Model test(String name, int age){}
     
    启动服务的时候,会报如下异常:

    Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.soft.framework.core.response.CommResponse com.soft.back.openplatform.api.AdvertApi.insertAdvertTactics(com.soft.back.openplatform.model.AdvertTactics,java.lang.String)

    异常原因:当使用Feign时,如果发送的是get请求,那么需要在请求参数前加上@RequestParam注解修饰,Controller里面可以不加该注解修饰。

    正确写法

    @RequestMapping(value="/test", method=RequestMethod.GET)
    public Model test(@RequestParam("name") String name, @RequestParam("age") int age){}
     

  • 相关阅读:
    flask数据库
    python 百万级别类实例实现节省内存
    python定义一种新类型的元组
    python使用临时文件
    open函数 文件设置缓冲
    词频统计,字典成绩排序
    列表数组集合解析
    2019蓝桥杯Java第十题大学生B组——最短路径思想
    项目企业信息图谱分析有感——数据分析
    需求分析有感
  • 原文地址:https://www.cnblogs.com/no8g/p/13415539.html
Copyright © 2020-2023  润新知