如何在运行时更改@FeignClient 名称 [英] how to change the @FeignClient name in runtime
本文介绍了如何在运行时更改@FeignClient 名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Spring Cloud Netflix 来构建我的微服务.
I use Spring Cloud Netflix to build my micro service .
@FeignClient(name = "ms-cloud",configuration = MsCloudClientConfig.class)
public interface TestClient {
/**
* @return
*/
@RequestMapping(value = "/test", method = RequestMethod.GET)
String test();
}
当某些特殊用户时,我想将名称更改为 ms-cloud-pre.谁能给点建议?
I want to change the name to ms-cloud-pre when some special user. Anyone can give some advice?
推荐答案
根据 documentation feign 支持 name
和 url中的占位符代码> 字段.
According to the documentation feign supports placeholders in the name
and url
fields.
@FeignClient(name = "${store.name}")
public interface StoreClient {
//..
}
因此您可以在运行时使用普通的 Spring Boot 配置机制设置 store.name=storeProd
.
So you could set store.name=storeProd
at runtime using normal spring boot configuration mechanisms.
这篇关于如何在运行时更改@FeignClient 名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文