系统介绍SpringCloud的各种组件的使用和实现原理。
Feign中使用动态服务名
@Component
public class DynamicFeignClient<T> {
private FeignClientBuilder feignClientBuilder;
public DynamicFeignClient(@Autowired ApplicationContext applicationContext) {
this.feignClientBuilder = new FeignClientBuilder(applicationContext);
}
public T getFeignClient(final Class<T> type, String serviceName) {
return this.feignClientBuilder.forType(type, serviceName).build();
}
}
使用示例:
// 依赖注入
@Autowired
DynamicFeignClient<ISysDictClient> client;
// 获取到Feign客户端
client.getFeignClient(ISysDictClient.class, serviceName).method(...);
Feign的实现原理
https://www.cnblogs.com/binarylei/p/11563023.html