久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

spring cloud Feign使用@RequestLine遇到的坑

瀏覽:2日期:2023-07-07 08:30:43
Feign使用@RequestLine遇到的坑

如何在微服務(wù)項目中調(diào)用其它項目的接口試使用spring cloud feign聲明式調(diào)用。

/** * 客戶端請去 * @author RAY * */@FeignClient(name='store',configuration=FooConfiguration .class)public interface UserFeignClient { @RequestLine('GET /simple/{id}') public User findById(@Param('id') Long id);}

但是啟動得時候報錯:

Method getLinksForTrack not annotated with HTTP method type (ex. GET, POST)

官方文檔說明

@RequestLine is a core Feign annotation, but you are using the Spring Cloud @FeignClientwhich uses Spring MVC annotations.

spring cloud Feign使用@RequestLine遇到的坑

意思就是feign 默認(rèn)使用的是spring mvc 注解(就是RequestMapping 之類的) ,所以需要通過新增一個配置類來修改其“契約”。

@Configurationpublic class FooConfiguration { @Bean public Contract feignContract() {return new feign.Contract.Default();//使用feign自帶契約 }}

PS : feignContract方法名不要跟一樣。否則啟動得時候會報錯。 得改一個跟類名不一樣得方法名!

@RequestLine的使用及配置

@RequestLine與其它請求不同,只需要簡單寫請求方式和路徑就能達(dá)到請求其它服務(wù)的目的。

@FeignClient(value = 'feign-server',configuration = FeignConfig.class) //需要一個配置文件public interface TestService { @RequestLine('POST /feign/test') //對應(yīng)請求方式和路徑 String feign(@RequestBody UserDO userDO);}

@EnableFeignClients@SpringBootConfigurationpublic class FeignConfig { @Bean public Contract contract(){return new feign.Contract.Default(); }}

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 林甸县| 周至县| 台州市| 香河县| 饶河县| 德兴市| 孟村| 济源市| 衢州市| 古田县| 长顺县| 富蕴县| 临猗县| 丹凤县| 黎平县| 西林县| 太仓市| 绥德县| 涿鹿县| 兴海县| 宜兰市| 荆州市| 丁青县| 牡丹江市| 江口县| 体育| 乐都县| 德钦县| 泗洪县| 灵石县| 神池县| 柏乡县| 五家渠市| 益阳市| 乐亭县| 乌鲁木齐县| 措美县| 凯里市| 墨江| 罗源县| 宝应县|