Skip to content

3.8.0的 WxRedisOps 打成jar包后会启动失败 #1605

Closed

Description

@refeccd

3.8.0的 WxRedisOps 打成jar包后会启动失败

模块版本情况

  • WxJava 模块名: 3.8.0
  • WxJava 版本号:3.8.0

升级3.8之前采用本地内存配置的方式启动,代码如下

@Bean
public WxMpService wxMpService(WechatProperties wechatProperties) {
    WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
    configStorage.setAppId(wechatProperties.getAppId());
    configStorage.setSecret(wechatProperties.getSecret());
    configStorage.setToken(wechatProperties.getToken());
    WxMpService wxMpService = new WxMpServiceImpl();
    wxMpService.setWxMpConfigStorage(configStorage);
    return wxMpService;
}

升级3.8.0之后,本地已经确认移除了jedis依赖,使用 StringRedisTemplate 的方式,代码如下

@Bean
public WxMpService wxMpService(WechatProperties wechatProperties, StringRedisTemplate stringRedisTemplate) {
    RedisTemplateWxRedisOps wxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplate);
    WxMpRedisConfigImpl configStorage = new WxMpRedisConfigImpl(wxRedisOps, "wx");
    configStorage.setAppId(wechatProperties.getAppId());
    configStorage.setSecret(wechatProperties.getSecret());
    configStorage.setToken(wechatProperties.getToken());
    WxMpService wxMpService = new WxMpServiceImpl();
    wxMpService.setWxMpConfigStorage(configStorage);
    return wxMpService;
}

日志

报错日志

Activity

  1. binarywang commented on Jun 5, 2020

    @binarywang
    Owner

    暂时把jedis加回来吧,目前的代码需要依赖,没有找到好的办法处理,如果你有,欢迎提交PR

  2. yuxicun commented on Jun 5, 2020

    @yuxicun

    我总结了下,必须添加
    redis.clients
    jedis
    2.10.2
    这个才能成功,版本是3.3的不行啊,跟踪了下代码,发现wx需要依赖2版本的

  3. binarywang commented on Jun 6, 2020

    @binarywang
    Owner

    确实目前依赖的是2.x版本的jedis

  4. lkqm commented on Jun 6, 2020

    @lkqm

    目前的解决只能把WxMpRedisConfigImpl的这个构造函数移除掉WxMpRedisConfigImpl(JedisPool jedisPool), 这样老本本就存在兼容问题。
    这里很奇怪, 即使我调用另外一个构造函数, 在打包后的jar执行中, 依然会去加载参数为JedisPool这个类.

  5. binarywang commented on Jun 6, 2020

    @binarywang
    Owner

    目前的解决只能把WxMpRedisConfigImpl的这个构造函数移除掉WxMpRedisConfigImpl(JedisPool jedisPool), 这样老本本就存在兼容问题。
    这里很奇怪, 即使我调用另外一个构造函数, 在打包后的jar执行中, 依然会去加载参数为JedisPool这个类.

    我觉得可以不必兼容老版本,如果想使用老版本,自行去修改实现吧

  6. lkqm commented on Jun 8, 2020

    @lkqm

    @binarywang 之前的结论是错的, 最后测试发现spring-boot加载WxMpStorageAutoConfiguration会去反射获取所有方法, 触发了类加载, 复现代码如下:

    public static void main(String[] args) {
            Method[] methods = WxMpStorageAutoConfiguration.class.getDeclaredMethods();
        }
    

    image

    目前没有办法解决, 也就是说jdk反射机制会触发JedisPool类加载, 不确定是不是jdk的一个bug

    环境:

    marioluo@MariodeMacBook-Pro ~ % java -version
    openjdk version "1.8.0_232"
    OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
    OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)
    

    日志: https://paste.ubuntu.com/p/NMjGDkD3TV/

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions