一、feign的原理
EnableFeignClients会引入一个FeignClientsRegistrar,他主要就是扫描@FeignClient注解的类,然后放到beanDefinition中。
他会生成一个JDK代理,利用的核心invocation就是 HystrixInvocationHandler,他会调用
LoadBalancerFeignClient,这个是核心的中转类,从这里就可以看到和ribbon类似了
URI asUri = URI.create(request.url());String clientName = asUri.getHost();URI uriWithoutHost = cleanUrl(request.url(), clientName);FeignLoadBalancer.RibbonRequest ribbonRequest = new FeignLoadBalancer.RibbonRequest(this.delegate, request, uriWithoutHost);IClientConfig requestConfig = getClientConfig(options, clientName);return lbClient(clientName).executeWithLoadBalancer(ribbonRequest,requestConfig).toResponse();