Skip to content
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

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

Closed
liaozan opened this issue Jun 4, 2020 · 6 comments
Closed

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

liaozan opened this issue Jun 4, 2020 · 6 comments

Comments

@liaozan
Copy link

liaozan commented Jun 4, 2020

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;
}

日志

报错日志

@binarywang
Copy link
Member

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

@yuxicun
Copy link

yuxicun commented Jun 5, 2020

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

@binarywang
Copy link
Member

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

@lkqm
Copy link

lkqm commented Jun 6, 2020

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

@binarywang
Copy link
Member

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

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

@lkqm
Copy link

lkqm commented Jun 8, 2020

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants