Skip to content

修复 wx-java-open-multi-spring-boot-starter 硬编码 HttpClient4 导致启动失败的问题#4060

Open
Copilot wants to merge 2 commits into
developfrom
copilot/fix-httpclient-dependency-issue
Open

修复 wx-java-open-multi-spring-boot-starter 硬编码 HttpClient4 导致启动失败的问题#4060
Copilot wants to merge 2 commits into
developfrom
copilot/fix-httpclient-dependency-issue

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

AbstractWxOpenConfiguration.configHttp() 无条件实例化 DefaultApacheHttpClientBuilder(HttpClient 4.x),而默认服务实现 WxOpenServiceImpl 实际使用 HttpClient 5.x,导致未显式引入 HttpClient4 依赖的项目启动时抛出 NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager

变更内容

  • WxOpenMultiProperties:新增 HttpClientType 枚举(APACHE_HTTP / HTTP_COMPONENTS),并在 ConfigStorage 中添加 httpClientType 字段,默认值为 HTTP_COMPONENTS

  • AbstractWxOpenConfiguration

    • wxOpenService() 根据 httpClientType 动态选择 WxOpenServiceApacheHttpClientImplWxOpenServiceHttpComponentsImpl
    • configHttp() 仅在 httpClientType == APACHE_HTTP 时才配置 DefaultApacheHttpClientBuilder

默认行为与原来一致(HttpClient 5.x),无需修改现有配置。如需切换至 HttpClient 4.x:

wx:
  open:
    config-storage:
      http-client-type: APACHE_HTTP

- 在 WxOpenMultiProperties.ConfigStorage 中新增 HttpClientType 枚举(APACHE_HTTP / HTTP_COMPONENTS)及 httpClientType 字段,默认值为 HTTP_COMPONENTS
- 修改 AbstractWxOpenConfiguration.wxOpenService() 根据 httpClientType 选择对应的 WxOpenServiceApacheHttpClientImpl 或 WxOpenServiceHttpComponentsImpl
- 修改 AbstractWxOpenConfiguration.configHttp() 仅在 httpClientType 为 APACHE_HTTP 时配置 DefaultApacheHttpClientBuilder,消除对 HttpClient4 的强制依赖

Closes #4059
Copilot AI changed the title [WIP] Fix HttpClient version dependency issue in wx-java-open-multi-spring-boot-starter 修复 wx-java-open-multi-spring-boot-starter 硬编码 HttpClient4 导致启动失败的问题 Jul 1, 2026
Copilot AI requested a review from binarywang July 1, 2026 02:00
@binarywang binarywang marked this pull request as ready for review July 1, 2026 09:18
Copilot AI review requested due to automatic review settings July 1, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 针对 wx-java-open-multi-spring-boot-starter 在未引入 HttpClient4 依赖时仍会硬编码初始化 DefaultApacheHttpClientBuilder、从而导致启动 NoClassDefFoundError 的问题,通过引入可配置的 HttpClient 类型选择,将 HttpClient4 相关初始化改为按需执行,确保默认(HttpClient5)路径不再触发类加载失败。

Changes:

  • WxOpenMultiProperties.ConfigStorage 中新增 httpClientType 配置项及枚举(默认 HTTP_COMPONENTS)。
  • AbstractWxOpenConfiguration.wxOpenService() 根据 httpClientType 选择不同的 WxOpenService 实现(HttpClient4 vs HttpClient5)。
  • configHttp() 仅在选择 HttpClient4 时才配置 DefaultApacheHttpClientBuilder,避免默认路径触发 HttpClient4 相关类加载。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
spring-boot-starters/wx-java-open-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenMultiProperties.java 增加 httpClientType 配置入口与枚举,默认使用 HttpClient5(HTTP_COMPONENTS)。
spring-boot-starters/wx-java-open-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/configuration/services/AbstractWxOpenConfiguration.java 根据配置选择 service 实现,并将 HttpClient4 超时配置改为仅在需要时执行,修复默认启动失败。

Comment on lines 76 to +80
public WxOpenService wxOpenService(WxOpenConfigStorage configStorage, WxOpenMultiProperties wxOpenMultiProperties) {
WxOpenService wxOpenService = new WxOpenServiceImpl();
WxOpenMultiProperties.HttpClientType httpClientType = wxOpenMultiProperties.getConfigStorage().getHttpClientType();
WxOpenService wxOpenService;
if (httpClientType == WxOpenMultiProperties.HttpClientType.APACHE_HTTP) {
wxOpenService = new WxOpenServiceApacheHttpClientImpl();
@augmentcode

augmentcode Bot commented Jul 1, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: 修复 wx-java-open-multi-spring-boot-starter 在未引入 HttpClient4 依赖时启动报 NoClassDefFoundError 的问题。

Changes:

  1. WxOpenMultiProperties.ConfigStorage 新增 httpClientType(默认 HTTP_COMPONENTS)。
  2. AbstractWxOpenConfiguration#wxOpenService 根据 httpClientType 选择 HttpClient4/5 对应实现。
  3. AbstractWxOpenConfiguration#configHttp 仅在选择 HttpClient4 时才配置 DefaultApacheHttpClientBuilder 超时参数。

    Note: 如需切换到 4.x,可配置 wx.open.config-storage.http-client-type=APACHE_HTTP

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

if (httpClientType == WxOpenMultiProperties.HttpClientType.APACHE_HTTP) {
wxOpenService = new WxOpenServiceApacheHttpClientImpl();
} else {
wxOpenService = new WxOpenServiceHttpComponentsImpl();

@augmentcode augmentcode Bot Jul 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractWxOpenConfiguration.java:82 这里默认从返回 WxOpenServiceImpl 改为 WxOpenServiceHttpComponentsImpl,可能影响依赖具体实现类型(强转/instanceof/按类注入)的用户代码。即使当前 WxOpenServiceImpl 只是别名类,这种实现类型变化仍有兼容性风险。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wx-java-open-multi-spring-boot-starter HttpClient 版本依赖问题

3 participants