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

1 篇文章 0 订阅
1 篇文章 0 订阅

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注解,但是,经过个人测试,发现并不是这个原因,两者都可正常访问。
官方示例,如图:
在这里插入图片描述
链接: netflix-feign-starter.

原因,及解决办法。

经过无休止的翻找,终于发现了原因,因为我提供服务的Servcie类,继承了其他Service,而父类中没有加映射注解如@RequestMapping或者@GetMapping/PostMapping。从而导致出现这个问题,去掉父类,或重写父类方法,再或者在父类方法中加上以上注解,就能正常启动了。
如图:
服务类
UserService子类
父类方法
在这里插入图片描述
所以出现了,该异常。

此外

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

—2021年3月更新
有相关解决方案,可以参考:
https://github.com/SpringCloud/venus-cloud-feign


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

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值