2021
02-26
02-26
完美解决SpringCloud-OpenFeign使用okhttp替换不生效问题
事发地原默认的Feign是使用URLConnector进行通信的,当换为okhttp时,直接引入包及配置以下内容根本不生效,还是走原生的。feign:okhttp:enable:true事件还原创建项目并引入pom相关的依赖如下:<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0https://mav...
继续阅读 >
思考:使用RestTemplate+ribbon已经可以完成服务间的调用,为什么还要使用feign?StringrestTemplateForObject=restTemplate.getForObject("http://服务名/url?参数"+name,String.class);存在问题:1.每次调用服务都需要写这些代码,存在大量的代码冗余2.服务地址如果修改,维护成本增高3.使用时不够灵活说明https://cloud.spring.io/spring-cloud-openfeign/reference/html/Feign是一个声明式的伪Http客户端,它使得写Http...