Skip to content

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

Description

@qichhhhh

提问前,请确保阅读过项目首页说明以及wiki开发文档相关内容,尤其是常见问题部分。完成内容后,请务必移除包括本句在内的无用内容,以免影响阅读,否则直接关闭,谢谢合作~

另外如果确认属于bug,而且已明确如何修复,请参考贡献指南直接提交PR,省的浪费时间在这里描述问题,非常感谢配合

简要描述

wx-java-open-multi-spring-boot-starter 在 AbstractWxOpenConfiguration.java 中硬编码了 HttpClient4 的相关代码,导致必须要显式引入多一个 HttpClient4 的依赖,否则无法正确启动项目

模块版本情况

  • WxJava 模块名: 4.8.3.B

日志

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wxOpenMultiServices' defined in class path resource [com/binarywang/spring/starter/wxjava/open/configuration/services/WxOpenInRedisTemplateConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.binarywang.spring.starter.wxjava.open.service.WxOpenMultiServices]: Factory method 'wxOpenMultiServices' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager

Activity

  1. qichhhhh commented on Jun 30, 2026

    @qichhhhh
    Author

    AbstractWxOpenConfiguration.java
    140 ~ 151 行
    // 设置自定义的HttpClient超时配置 ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder(); if (clientBuilder == null) { clientBuilder = DefaultApacheHttpClientBuilder.get(); } if (clientBuilder instanceof DefaultApacheHttpClientBuilder) { DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder; defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout()); defaultBuilder.setSoTimeout(storage.getSoTimeout()); defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout()); config.setApacheHttpClientBuilder(defaultBuilder); }

  2. added a commit that references this issue on Jul 1, 2026
    3f0b6cb
  3. qichhhhh commented on Jul 1, 2026

    @qichhhhh
    Author

    还需要在 AbstractWxOpenConfiguration#wxOpenMultiServices 方法中进行 HttpClient5 的超时配置

            WxOpenMultiServicesImpl services = new WxOpenMultiServicesImpl();
            WxOpenMultiProperties.ConfigStorage storageProps = wxOpenMultiProperties.getConfigStorage();
    
            **// 在首个 WxOpenService 初始化前设置 httpclient 5.x 超时
            // DefaultHttpComponentsClientBuilder 是单例,prepare() 仅执行一次
            configHttpComponentsTimeout(storageProps);**
    
            for (Map.Entry<String, WxOpenSingleProperties> entry : appsMap.entrySet()) {
                String tenantId = entry.getKey();
                WxOpenSingleProperties appProperties = entry.getValue();
    
                WxOpenInRedisTemplateConfigStorage config = configRedisTemplate();
                configApp(config, appProperties);
                configHttp(config, storageProps);
    
                // setWxOpenConfigStorage 会触发 initHttp(),使用 httpclient 5.x 构建 CloseableHttpClient
                WxOpenService wxOpenService = new WxOpenServiceImpl();
                wxOpenService.setWxOpenConfigStorage(config);
    
                services.addWxOpenService(tenantId, wxOpenService);
            }
    
        /**
         * 在 httpclient 5.x 单例 builder 上设置超时参数,替代 starter 中无效的 4.x 超时设置。
         *
         * <p>
         * 必须在 {@code WxOpenServiceImpl.setWxOpenConfigStorage()}(触发 initHttp ->
         * build -> prepare)之前调用, 因为 prepare() 受 AtomicBoolean 保护仅执行一次。</p>
         */
        private void configHttpComponentsTimeout(WxOpenMultiProperties.ConfigStorage storage) {
            DefaultHttpComponentsClientBuilder builder = DefaultHttpComponentsClientBuilder.get();
            builder.setConnectionTimeout(storage.getConnectionTimeout());
            builder.setSoTimeout(storage.getSoTimeout());
            builder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
        }
    
  4. qichhhhh commented on Jul 1, 2026

    @qichhhhh
    Author

    相应的之前 HttpClient4 相关的超时配置代码也要移到循环体之外

  5. binarywang commented on Jul 1, 2026

    @binarywang
    Owner

    请直接提交PR,谢谢

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

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions