Spring Cloud Feign 使用feign client时遇到的一个坑
来源:互联网 发布:刷钻平台源码 编辑:程序博客网 时间:2024/06/07 14:01
使用feign 的时候遇到了一个坑,不知道有没有人也遇到。
可是编译会出现如下错误:
编译就通过了。
问题描述:
定义好 feign client的interface以后 的java代码
@FeignClient(value = "test")public interface TeacApiClient { @RequestMapping(method = RequestMethod.GET, value = "/{test}") public Object saveUpVersion(@Param("test") String test);}
为了使用consul动态发现服务的url,所以需要自己构建Feign的client:
this.httpClient = Feign.builder().logLevel(Logger.Level.BASIC).target(TeacApiClient.class, url);
可是编译会出现如下错误:
Caused by: java.lang.IllegalStateException: Method saveUpVersion not annotated with HTTP method type (ex. GET, POST)at feign.Util.checkState(Util.java:128) ~[feign-core-9.5.0.jar:na]at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:97) ~[feign-core-9.5.0.jar:na]at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64) ~[feign-core-9.5.0.jar:na]at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146) ~[feign-core-9.5.0.jar:na]at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53) ~[feign-core-9.5.0.jar:na]at feign.Feign$Builder.target(Feign.java:218) ~[feign-core-9.5.0.jar:na]at feign.Feign$Builder.target(Feign.java:214) ~[feign-core-9.5.0.jar:na]at se.ericsson.bid.teso.saveupversion.services.TeacSaveUpVersionService.buildUpHttpClient(TeacSaveUpVersionService.java:49) ~[classes/:na]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:701) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]... 30 common frames omitted
但是使用
@RequestLine("POST /{test}") public Object saveUpVersion(@Param("test") String test);
编译就通过了。
可是总觉得这样写不太优雅。
解决方法:
官方文档也是用的@RequestMapping并没有这个问题, google了好久也没有好的解决方案,隐约感觉用该是feign使用的 mvn contract不太对,因为有人讨论 使用default feign contract 会出现同样的问题,所以代码改成:this.httpClient = Feign.builder().logLevel(Logger.Level.BASIC).contract(new SpringMvcContract()).target(TeacApiClient.class, url);
就可以了。应该是默认使用的Contract.default并不支持spring 的requestmapping标签.
或者:
使用 FeignClientsConfiguration 中生成的contract
@Import(FeignClientsConfiguration.class)public class xxx { @Autowired private void buildUpHttpClient(Contract contract) { this.httpClient = Feign.builder() .contract(contract) .target(TeacApiClient.class, getTeacUrl()); }
阅读全文
0 0
- Spring Cloud Feign 使用feign client时遇到的一个坑
- spring cloud oauth2 feign 遇到的坑
- spring cloud 使用feign 遇到问题
- Spring Cloud feign使用
- spring cloud-Feign使用中遇到的问题总结
- Spring Cloud Feign 的使用注意事项
- Spring Cloud Feign 使用方式
- spring-cloud-feign集成feign的几个注意事项
- Spring Cloud(Netflix) Feign: 以Dubbo暴露服务的方式使用Feign
- Spring Cloud feign
- Spring Cloud Feign诠释
- spring cloud-feign
- Spring Cloud Feign常见问题
- spring cloud Feign
- spring cloud feign
- Spring Cloud Feign
- Spring Cloud Feign
- spring-cloud【Feign】
- 立flag
- shiro权限管理简易整理
- Git入门学习笔记(二) 远程仓库
- CentOS7 Tomcat 实时查看运行日志打印
- Django系列教程(5)-- 视图URLconf及视图函数的定义
- Spring Cloud Feign 使用feign client时遇到的一个坑
- 再回首html和css
- 吴恩达学习-浅层神经网络
- 8G内存可以建立多少个tcp长连接?
- HTML语言编码charset不要写在标题<title>的下面
- 使用junit4.12作单元测试报Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescrib
- QT控件大全 三十 QGumPush
- Python练习数据结构笔记
- 如何得到跟原图大小一样大,只包含ROI区域图像