启动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}

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2022-02-05
  • 2022-02-12
  • 2021-05-29
  • 2022-12-23
  • 2022-01-15
猜你喜欢
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-06-28
  • 2021-04-02
  • 2021-12-29
相关资源
相似解决方案