SpringCloud微服務中@FeignClient使用和發現服務場中的其他服務

首先需要在Application應用啓動中需添加@EnableFeignClients註解。

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(value = "com.xxx.service")
public class XXXApplication {
    public static void main(String[] args) {
        SpringApplication.run(XXXApplication.class,args);
    }
}

使用FeignClients調用服務場中的註冊的微服務

@FeignClient(value = "XXX-SERVER")
public interface FeignService {
    
    @RequestMapping(value = "/xxx/check_token",method = RequestMethod.GET)
    String getUser(@RequestParam(value = "token", required = true) String token);

}

參考資料:

https://blog.csdn.net/ZYC88888/article/details/81291684

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章