-
-
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 <[email protected]>
Co-authored-by: binarywang <[email protected]>
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 升级迁移指南,包括升级原因、影响、迁移步骤和常见问题 |
docs/HTTPCLIENT_UPGRADE_GUIDE.md
Outdated
| <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或最新版本来避免混淆
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 替换为通用描述(如 4.7.x 和 最新版本),避免版本号硬编码导致的维护问题。提交: 154da92
| * 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 中使用一致的枚举命名风格。
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 中添加说明。Multi-Starter 使用 HTTP_COMPONENTS(大写下划线格式),单体 Starter 使用 HttpComponents(PascalCase)。枚举命名风格保持现状以维持向后兼容性,但通过文档明确说明了使用方式。提交: 154da92
| */ | ||
| 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. |
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.
已统一。所有枚举类型现在使用简洁的注释风格(如 HttpComponents.),与现有枚举值保持一致。提交: 154da92
...-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java
Outdated
Show resolved
Hide resolved
| ```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 的枚举命名风格。
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 中添加专门说明。明确指出单体 Starter 使用 HttpComponents,Multi-Starter 使用 HTTP_COMPONENTS,避免用户配置时的困惑。提交: 154da92
README.md
Outdated
| 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 配置,如果不支持,应从文档描述中移除。
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.
已更正。将文档中的描述修改为 "CP 模块的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档",更准确地反映了实际支持情况。提交: 154da92
| /** | ||
| * 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 一致,存在同样的问题。建议统一所有枚举值的注释详细程度。
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 相关插件的枚举注释现在使用简洁一致的风格。提交: 154da92
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…in/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java Co-authored-by: Copilot <[email protected]>
|
@copilot apply changes based on the comments in this thread |
- 修复文档中的版本号引用,使用通用版本描述 - 更正 CP 模块支持说明,明确其支持情况取决于具体 Starter 版本 - 添加 Multi-Starter 枚举命名格式说明 - 统一所有枚举类型的注释风格,使用简洁格式 Co-authored-by: binarywang <[email protected]>
升级到 Apache HttpClient 5.x 作为默认 HTTP 客户端
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.