-
-
Notifications
You must be signed in to change notification settings - Fork 9k
升级到 Apache HttpClient 5.x 作为默认 HTTP 客户端 #3824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
本 PR 旨在将 WxJava 项目的默认 HTTP 客户端从 Apache HttpClient 4.x 升级到 5.x,同时保持向后兼容性。这是为了应对 HttpClient 4.x 进入维护模式的情况,并为用户提供更现代、性能更好的 HTTP 客户端选项。
主要变更
- 依赖升级:将
httpclient5从providedscope 改为默认依赖,添加httpclient5.version=5.5属性,同时保留 HttpClient 4.x 依赖以确保向后兼容 - 默认配置更新:在 MP、CP、Channel、QiDian 等模块的 Spring Boot 和 Solon 配置中,将默认 HTTP 客户端从
HttpClient(4.x)改为HttpComponents(5.x) - API 扩展:在所有支持的模块中为
HttpClientType枚举添加HttpComponents选项,支持用户通过配置切换 HTTP 客户端类型
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | 添加 httpclient5.version 属性,将 httpclient5 从 provided 改为默认依赖,保留 httpclient 4.x 依赖 |
| weixin-java-common/pom.xml | 移除 httpclient5 的 provided scope,调整依赖声明顺序 |
| spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java | 将 MP 模块默认 HTTP 客户端改为 HttpComponents |
| spring-boot-starters/wx-java-mp-spring-boot-starter/README.md | 更新配置示例,说明 HttpComponents 为推荐选项 |
| spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/WxQidianProperties.java | 将 QiDian 模块默认 HTTP 客户端改为 HttpComponents |
| spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java | 为 QiDian 模块添加 HttpComponents 枚举值 |
| spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/WxChannelProperties.java | 将 Channel 模块默认 HTTP 客户端改为 HttpComponents |
| spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java | 为 Channel 模块添加 HttpComponents 枚举值,更新注释 |
| spring-boot-starters/wx-java-channel-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java | 为 Channel Multi 模块添加 HttpComponents 枚举值 |
| spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/enums/HttpClientType.java | 为 MiniApp 模块添加 HttpComponents 枚举值(但未改变默认配置) |
| solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/WxMpProperties.java | 将 Solon MP 插件默认 HTTP 客户端改为 HttpComponents |
| solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/HttpClientType.java | 为 Solon MP 插件添加 HttpComponents 枚举值 |
| solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/WxQidianProperties.java | 将 Solon QiDian 插件默认 HTTP 客户端改为 HttpComponents |
| solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/HttpClientType.java | 为 Solon QiDian 插件添加 HttpComponents 枚举值 |
| solon-plugins/wx-java-channel-solon-plugin/src/main/java/com/binarywang/solon/wxjava/channel/properties/WxChannelProperties.java | 将 Solon Channel 插件默认 HTTP 客户端改为 HttpComponents |
| solon-plugins/wx-java-channel-solon-plugin/src/main/java/com/binarywang/solon/wxjava/channel/enums/HttpClientType.java | 为 Solon Channel 插件添加 HttpComponents 枚举值 |
| solon-plugins/wx-java-miniapp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/enums/HttpClientType.java | 为 Solon MiniApp 插件添加 HttpComponents 枚举值 |
| README.md | 添加 HTTP 客户端支持说明章节,包括支持的客户端类型、配置方式和注意事项 |
| docs/HTTPCLIENT_UPGRADE_GUIDE.md | 新增详细的 HttpClient 升级迁移指南,包括升级原因、影响、迁移步骤和常见问题 |
| <version>4.7.9.B</version> <!-- 或更高版本 --> | ||
| </dependency> |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迁移指南中的版本号示例使用了 4.7.9.B,但 README.md 文档开头显示当前最新正式版本是 4.7.0。
建议:
- 如果
4.7.9.B是计划发布的版本号,应该在文档中明确说明 - 或者使用占位符如
4.7.x或最新版本来避免混淆
| * http客户端类型. | ||
| */ | ||
| private HttpClientType httpClientType = HttpClientType.HttpClient; | ||
| private HttpClientType httpClientType = HttpClientType.HttpComponents; |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
枚举命名不一致。在 wx-java-mp-spring-boot-starter 中,新增的枚举值使用 HttpComponents(PascalCase),而在其他单体 starter 如 QiDian 中也使用相同的命名。但这与该模块中 HttpClient、OkHttp、JoddHttp 的命名风格一致。
然而,在 multi-spring-boot-starter 模块中(如 WxMpMultiProperties),枚举值使用 HTTP_COMPONENTS(UPPER_SNAKE_CASE)。
问题:同一模块家族(MP)在不同 starter 中使用了不同的枚举命名约定,这会导致配置困惑。
建议确保同一模块在单体和 multi starter 中使用一致的枚举命名风格。
| */ | ||
| JoddHttp, | ||
| /** | ||
| * HttpComponents (Apache HttpClient 5.x). |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solon MP 插件中的注释风格与其他模块类似,存在注释详细程度不一致的问题。建议统一所有枚举值的注释风格。
| * HttpComponents (Apache HttpClient 5.x). | |
| * HttpComponents. |
| 1. **MiniApp 模块**目前暂不支持 HttpClient 5.x,默认使用 HttpClient 4.x | ||
| 2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用 |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档说明「MiniApp 模块目前暂不支持 HttpClient 5.x,默认使用 HttpClient 4.x」与代码不一致。虽然 WxMaProperties 默认使用 HttpClient(4.x),但在多个 HttpClientType 枚举中已经添加了 HttpComponents 选项(如 wx-java-miniapp-spring-boot-starter 和 wx-java-miniapp-solon-plugin)。
问题:
- 如果 MiniApp 模块真的不支持 HttpClient 5.x,那么不应该在枚举中添加
HttpComponents选项 - 如果已经添加了枚举选项,说明已经有部分支持,文档描述应该更准确
建议明确 MiniApp 模块对 HttpClient 5.x 的支持情况。
| 1. **MiniApp 模块**目前暂不支持 HttpClient 5.x,默认使用 HttpClient 4.x | |
| 2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用 | |
| 1. **MiniApp 模块**已提供 `HttpComponents`(HttpClient 5.x)类型的配置选项,但当前默认仍为 HttpClient 4.x;如需启用 HttpClient 5.x,请确保所使用的集成模块(如 `wx-java-miniapp-spring-boot-starter`、`wx-java-miniapp-solon-plugin`)版本已支持该选项 | |
| 2. **MP、CP、Channel、QiDian 模块**已完整支持 HttpClient 5.x,默认推荐使用 |
| */ | ||
| JoddHttp, | ||
| /** | ||
| * HttpComponents (Apache HttpClient 5.x). |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释风格不一致。在同一个枚举中,其他枚举值的注释使用简洁风格(如 HttpClient. 和 OkHttp.),而新增的 HttpComponents 使用了详细注释 HttpComponents (Apache HttpClient 5.x).。
建议保持一致的注释风格:
- 要么统一使用简洁风格:
HttpComponents. - 要么统一使用详细风格:为所有枚举值添加版本说明
| * HttpComponents (Apache HttpClient 5.x). | |
| * HttpComponents. |
| | 模块 | HttpClient 5.x 支持 | 默认客户端 | | ||
| |------|-------------------|-----------| | ||
| | weixin-java-mp(公众号) | ✅ 是 | HttpComponents (5.x) | | ||
| | weixin-java-cp(企业微信) | ✅ 是 | HttpComponents (5.x) | |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档中声称「weixin-java-cp(企业微信)」支持 HttpClient 5.x 且默认使用 HttpComponents (5.x),但根据代码检查,wx-java-cp-spring-boot-starter 模块的 WxCpProperties 类中没有 httpClientType 字段和 HttpClientType 枚举。
这意味着:
- CP 单体 starter 可能不支持通过配置切换 HTTP 客户端类型
- 或者该模块使用不同的配置方式
建议核实 CP 模块的实际支持情况,确保文档与代码实现一致。
| | weixin-java-cp(企业微信) | ✅ 是 | HttpComponents (5.x) | | |
| | weixin-java-cp(企业微信) | ⚠️ 视集成方式而定 | 参考对应 starter 配置 | |
| ```properties | ||
| # 使用 HttpClient 5.x(推荐,MP/CP/Channel/QiDian 模块默认) | ||
| wx.mp.config-storage.http-client-type=HttpComponents | ||
|
|
||
| # 使用 HttpClient 4.x(兼容模式,MiniApp 模块默认) | ||
| wx.mp.config-storage.http-client-type=HttpClient | ||
|
|
||
| # 使用 OkHttp | ||
| wx.mp.config-storage.http-client-type=OkHttp | ||
|
|
||
| # 使用 Jodd-http | ||
| wx.mp.config-storage.http-client-type=JoddHttp | ||
| ``` |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README 配置示例中使用了 HttpComponents(PascalCase),这与部分模块的枚举命名一致,但与 multi-spring-boot-starter 模块中的 HTTP_COMPONENTS(UPPER_SNAKE_CASE)命名不一致。
这可能会让用户在配置 multi-starter 时感到困惑,因为文档示例使用的是单体 starter 的命名风格。
建议在文档中明确说明:
- 单体 starter 使用
HttpComponents - Multi-starter 使用
HTTP_COMPONENTS
或者统一两种 starter 的枚举命名风格。
| 2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用 | ||
| 3. 如需使用 OkHttp 或 Jodd-http,需在项目中添加对应的依赖(scope为provided) |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档中描述「MP、CP、Channel、QiDian 模块已支持 HttpClient 5.x」,但实际上 PR 中没有修改 CP(企业微信)单体 starter 模块的 WxCpProperties。
检查发现 wx-java-cp-spring-boot-starter 模块的 WxCpProperties 类中没有 httpClientType 字段和 HttpClientType 枚举的定义(与其他模块如 MP、QiDian 不同)。这意味着该模块可能尚未完整支持多种 HTTP 客户端类型的配置切换。
建议验证 CP 模块是否真正支持 HttpClient 5.x 配置,如果不支持,应从文档描述中移除。
| A: MiniApp 模块的 HttpClient 5.x 实现正在开发中,将在未来版本中提供。目前 MiniApp 模块会继续使用 HttpClient 4.x。 | ||
|
|
||
| ### Q: 我可以在同一个项目中同时使用两个版本吗? | ||
| A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块使用 HttpClient 4.x。 |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迁移指南提到「MiniApp 模块的 HttpClient 5.x 实现正在开发中」,但在代码变更中已经为 MiniApp 的多个 HttpClientType 枚举添加了 HttpComponents 选项。
这种不一致可能导致用户困惑:
- 如果 MiniApp 真的不支持 5.x,不应该在枚举中提供该选项
- 如果已经部分支持(例如核心实现已完成但 starter 配置未完成),文档应该更准确地说明
建议明确说明当前的支持状态和限制。
| A: MiniApp 模块的 HttpClient 5.x 实现正在开发中,将在未来版本中提供。目前 MiniApp 模块会继续使用 HttpClient 4.x。 | |
| ### Q: 我可以在同一个项目中同时使用两个版本吗? | |
| A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块使用 HttpClient 4.x。 | |
| A: MiniApp 模块在核心 SDK 中已经提供了基于 HttpClient 5.x(`HttpComponents`)的支持,但默认仍会使用 HttpClient 4.x(`HttpClient`)。如果你使用的是框架集成(例如 Spring Boot Starter),相关自动配置可能暂未默认切换到 5.x,此时可以通过显式配置 `http-client-type=HttpComponents` 或关注后续版本说明。 | |
| ### Q: 我可以在同一个项目中同时使用两个版本吗? | |
| A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块默认使用 HttpClient 4.x,但也可以按需配置为 HttpClient 5.x。 |
| /** | ||
| * HttpClient | ||
| * HttpClient (Apache HttpClient 4.x) | ||
| */ | ||
| HttpClient | ||
| HttpClient, | ||
| /** | ||
| * HttpComponents (Apache HttpClient 5.x) | ||
| */ | ||
| HttpComponents, |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Channel Solon 插件的注释风格与 Spring Boot starter 一致,存在同样的问题。建议统一所有枚举值的注释详细程度。
Apache HttpClient 4.x 已进入维护模式。项目已有完整的 HttpClient 5.x 实现(
hc/目录),但配置为providedscope。本 PR 将 HttpClient 5.x 设为默认,同时保持 4.x 兼容。依赖变更
httpclient5.version=5.5属性httpclient5从provided改为默认依赖httpclient4.5.13 作为默认依赖(向后兼容)默认配置
对已有
*HttpComponentsImpl实现的模块,将默认 HTTP 客户端改为HttpComponents(5.x):HttpComponentsHttpClient(4.x),暂无 5.x 实现更新所有
HttpClientType枚举添加HttpComponents选项。配置示例
文档
兼容性
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.