最近在工作中遇到了一个Fegin传参异常,特此记录便于日后查阅。
java.lang.IllegalArgumentException: Body parameter 0 was null
at feign.Util.checkArgument(Util.java:102)
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:343)
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:213)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:72)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy88.productTypeBatchSetRedis(Unknown Source)
at com.openailab.oascloud.security.crontab.ProductTypeCacheCron.lambda$configureTasks$0(ProductTypeCacheCron.java:38)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
造成这个错误的原因是,我在服务a 调用服务b 的时候参数传递的是null,而服务b通过 @RequestBody 来接收参数,@RequestBody 的 required 默认值是true。
解决方法:
@RequestBody(required=false)或者传参数时限制参数不能为null。
版权声明:本文为qq_42322632原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。