使用okhttp替换Feign默认Client

mac2025-12-13  1

一 关键pom

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Cloud OpenFeign的Starter的依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-okhttp</artifactId> </dependency> </dependencies>

二 核心配置

server: port: 8011 spring: application: name: ch4-3-okhttp feign: httpclient: enabled: false okhttp: enabled: true

三 其他代码位置

https://github.com/cakin24/spring-cloud-code/tree/master/ch4-3/ch4-3-okhttp

四 运行测试

 

最新回复(0)