异常Caused by: java.lang.IllegalStateException: Method has too many Body parameters
Posted 天道酬勤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常Caused by: java.lang.IllegalStateException: Method has too many Body parameters相关的知识,希望对你有一定的参考价值。
出现此异常原因是引文使用feign客户端的时候,参数没有用注解修饰
1.1GET方式
错误写法
@RequestMapping(value="/test", method=RequestMethod.GET)
Model test(final String name, final int age);
启动服务的时候,会报如下异常:
Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.chhliu.springboot.restful.vo.User com.chhliu.springboot.restful.feignclient.UserFeignClient.findByUsername(java.lang.String,java.lang.String)
异常原因:当使用Feign时,如果发送的是get请求,那么需要在请求参数前加上@RequestParam注解修饰,Controller里面可以不加该注解修饰。
正确写法
@RequestMapping(value="/test", method=RequestMethod.GET)
Model test(@RequestParam("name") final String name,@RequestParam("age") final int age);
1.1POST方式
错误写法
public int save(@RequestBody final Person p, @RequestBody final UserModel user);
feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody。
正确写法
public int save(@RequestBody final Person p,@RequestParam("userId") String userId,@RequestParam("userTel") String userTel);
以上是关于异常Caused by: java.lang.IllegalStateException: Method has too many Body parameters的主要内容,如果未能解决你的问题,请参考以下文章
异常Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationExcep
java 使用反射创建对象时异常 InstantiationException: Caused by: java.lang.NoSuchMethodException:
异常Caused by: java.lang.IllegalStateException: Method has too many Body parameters
1.spring异常:Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor(示例
AndroidStudio启动异常:Caused by: java.lang.IllegalArgumentException: Argument for @NotNull paramet
hibernate 出现Caused by: java.sql.SQLException: Column 'id' not found.异常