SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法

异常分析

异常日志:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com...UserService’: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method remove not annotated with HTTP method type (ex. GET, POST)

项目中遇到该问题,在网上搜索了下,发现有同学说是使用@GetMapping/@PostMapping 的原因,虽然官方示例使用的是@RequestMapping注解,但是,经过个人测试,发现并不是这个原因,两者都可正常访问。
官方示例,如图:
SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法
链接: netflix-feign-starter.

原因,及解决办法。

经过无休止的翻找,终于发现了原因,因为我提供服务的Servcie类,继承了其他Service,而父类中没有加映射注解如@RequestMapping或者@GetMapping/PostMapping。从而导致出现这个问题,去掉父类,或重写父类方法,再或者在父类方法中加上以上注解,就能正常启动了。
如图:
服务类
SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法
父类方法
SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法
所以出现了,该异常。

此外

@FeignClient 注解 对 服务接口也有一定要求 如:
1.接口不是泛型接口,不含有类型参数。
2.接口最多只有1个父类接口,且其父类接口不能再含有父类接口。
3.接口不支持重写父类方法。等


以上内容,因为精力有限,没能仔细查看源码并分析原因,故准确性有待考证,仅供参考,有知道缘由的小伙伴,欢迎评论下方留言。希望对大家有帮助。
参考文档:https://blog.csdn.net/qq_39470742/article/details/83623577

相关文章:

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