异常分析
异常日志:
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。从而导致出现这个问题,去掉父类,或重写父类方法,再或者在父类方法中加上以上注解,就能正常启动了。
如图:
服务类
父类方法
所以出现了,该异常。
此外
@FeignClient 注解 对 服务接口也有一定要求 如:
1.接口不是泛型接口,不含有类型参数。
2.接口最多只有1个父类接口,且其父类接口不能再含有父类接口。
3.接口不支持重写父类方法。等
—2021年3月更新
有相关解决方案,可以参考:
https://github.com/SpringCloud/venus-cloud-feign
以上内容,因为精力有限,没能仔细查看源码并分析原因,故准确性有待考证,仅供参考,有知道缘由的小伙伴,欢迎评论下方留言。希望对大家有帮助。