這篇文章主要介紹“spring cloud中FeignClientFactoryBean的原理和作用是什么”,在日常操作中,相信很多人在spring cloud中FeignClientFactoryBean的原理和作用是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”spring cloud中FeignClientFactoryBean的原理和作用是什么”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)公司是專業(yè)的湟中網(wǎng)站建設(shè)公司,湟中接單;提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行湟中網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
本文主要研究一下spring cloud的FeignClientFactoryBean
spring-cloud-openfeign-core-2.2.0.M1-sources.jar!/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
class FeignClientFactoryBean implements FactoryBean
FeignClientFactoryBean實現(xiàn)了FactoryBean的getObject、getObjectType、isSingleton方法;實現(xiàn)了InitializingBean的afterPropertiesSet方法;實現(xiàn)了ApplicationContextAware的setApplicationContext方法
getObject調(diào)用的是getTarget方法,它從applicationContext取出FeignContext,然后構(gòu)造Feign.Builder并設(shè)置了logger、encoder、decoder、contract,之后通過configureFeign根據(jù)FeignClientProperties來進一步配置Feign.Builder的retryer、errorDecoder、request.Options、requestInterceptors、queryMapEncoder、decode404
初步配置完Feign.Builder之后再判斷是否需要loadBalance,如果需要則通過loadBalance方法來設(shè)置,不需要則在Client是LoadBalancerFeignClient的時候進行unwrap
spring-cloud-openfeign-core-2.2.0.M1-sources.jar!/org/springframework/cloud/openfeign/FeignClientProperties.java
@ConfigurationProperties("feign.client") public class FeignClientProperties { private boolean defaultToProperties = true; private String defaultConfig = "default"; private Mapconfig = new HashMap<>(); public boolean isDefaultToProperties() { return this.defaultToProperties; } public void setDefaultToProperties(boolean defaultToProperties) { this.defaultToProperties = defaultToProperties; } public String getDefaultConfig() { return this.defaultConfig; } public void setDefaultConfig(String defaultConfig) { this.defaultConfig = defaultConfig; } public Map getConfig() { return this.config; } public void setConfig(Map config) { this.config = config; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FeignClientProperties that = (FeignClientProperties) o; return this.defaultToProperties == that.defaultToProperties && Objects.equals(this.defaultConfig, that.defaultConfig) && Objects.equals(this.config, that.config); } @Override public int hashCode() { return Objects.hash(this.defaultToProperties, this.defaultConfig, this.config); } /** * Feign client configuration. */ public static class FeignClientConfiguration { private Logger.Level loggerLevel; private Integer connectTimeout; private Integer readTimeout; private Class retryer; private Class errorDecoder; private List > requestInterceptors; private Boolean decode404; private Class decoder; private Class encoder; private Class contract; public Logger.Level getLoggerLevel() { return this.loggerLevel; } public void setLoggerLevel(Logger.Level loggerLevel) { this.loggerLevel = loggerLevel; } public Integer getConnectTimeout() { return this.connectTimeout; } public void setConnectTimeout(Integer connectTimeout) { this.connectTimeout = connectTimeout; } public Integer getReadTimeout() { return this.readTimeout; } public void setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; } public Class getRetryer() { return this.retryer; } public void setRetryer(Class retryer) { this.retryer = retryer; } public Class getErrorDecoder() { return this.errorDecoder; } public void setErrorDecoder(Class errorDecoder) { this.errorDecoder = errorDecoder; } public List > getRequestInterceptors() { return this.requestInterceptors; } public void setRequestInterceptors( List > requestInterceptors) { this.requestInterceptors = requestInterceptors; } public Boolean getDecode404() { return this.decode404; } public void setDecode404(Boolean decode404) { this.decode404 = decode404; } public Class getDecoder() { return this.decoder; } public void setDecoder(Class decoder) { this.decoder = decoder; } public Class getEncoder() { return this.encoder; } public void setEncoder(Class encoder) { this.encoder = encoder; } public Class getContract() { return this.contract; } public void setContract(Class contract) { this.contract = contract; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FeignClientConfiguration that = (FeignClientConfiguration) o; return this.loggerLevel == that.loggerLevel && Objects.equals(this.connectTimeout, that.connectTimeout) && Objects.equals(this.readTimeout, that.readTimeout) && Objects.equals(this.retryer, that.retryer) && Objects.equals(this.errorDecoder, that.errorDecoder) && Objects.equals(this.requestInterceptors, that.requestInterceptors) && Objects.equals(this.decode404, that.decode404) && Objects.equals(this.encoder, that.encoder) && Objects.equals(this.decoder, that.decoder) && Objects.equals(this.contract, that.contract); } @Override public int hashCode() { return Objects.hash(this.loggerLevel, this.connectTimeout, this.readTimeout, this.retryer, this.errorDecoder, this.requestInterceptors, this.decode404, this.encoder, this.decoder, this.contract); } } }
FeignClientProperties有個Map結(jié)構(gòu)的config,key是feign client的名稱,默認是default,value是FeignClientConfiguration;FeignClientConfiguration包含了loggerLevel、connectTimeout、readTimeout、retryer、errorDecoder、requestInterceptors、decode404、decoder、encoder、contract屬性
FeignClientFactoryBean實現(xiàn)了FactoryBean的getObject、getObjectType、isSingleton方法;實現(xiàn)了InitializingBean的afterPropertiesSet方法;實現(xiàn)了ApplicationContextAware的setApplicationContext方法
getObject調(diào)用的是getTarget方法,它從applicationContext取出FeignContext,然后構(gòu)造Feign.Builder并設(shè)置了logger、encoder、decoder、contract,之后通過configureFeign根據(jù)FeignClientProperties來進一步配置Feign.Builder的retryer、errorDecoder、request.Options、requestInterceptors、queryMapEncoder、decode404
初步配置完Feign.Builder之后再判斷是否需要loadBalance,如果需要則通過loadBalance方法來設(shè)置,不需要則在Client是LoadBalancerFeignClient的時候進行unwrap
到此,關(guān)于“spring cloud中FeignClientFactoryBean的原理和作用是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
當(dāng)前題目:springcloud中FeignClientFactoryBean的原理和作用是什么
文章鏈接:http://weahome.cn/article/gdgogd.html