启动spring boot项目报错feign.FeignException$NotFound: status 404 reading

时间:2024-04-04 09:34:05

启动spring boot项目报错feign.FeignException$NotFound: status 404 reading

今早启动项目输入http://localhost/consumer/user?id=28,浏览器却返回Whitelabel Error Page,结果发现是queryUserById方法上GetMapping路径写错了。

启动spring boot项目报错feign.FeignException$NotFound: status 404 reading

因为方法上使用的是@RequestParam,上面@GetMapping里面不需要加/{id},所以在访问url是会报404。
因为项目中使用了Feign,我在UserClient类上加了@FeignClient(value = “service-provider”,fallback = UserClientFallback.class)注解,这里的value = "service-provider"是指去找provider方的方法,所以consumer和provider中的queryUserById方法要一样,不能一个用@RequestParam一个用@RequestParam,不然的话访问http://localhost/consumer/user?id=28也会报404。

启动spring boot项目报错feign.FeignException$NotFound: status 404 reading
启动spring boot项目报错feign.FeignException$NotFound: status 404 reading

附:@RequestParam和@RequestParam区别

@RequestParam与@PathVariable都可以用于在Controller层接收前端传递的数据。
用@RequestParam时,URL是:http://localhost/consumer/user?id=28,@GetMapping(“user”),user后面不需要加/{id}
用@PathVariable时,URL是:http://localhost/consumer/user/28,@GetMapping(“user/{id}”),user后面要加{id}