脚本宝典收集整理的这篇文章主要介绍了使用 redisson 时遇到的问题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
为了使用 redis 的分布式可重入锁, 决定引入 redisson
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.4.4</version>
</dependency>
代码
Config config = new Config();
config.setUseLinuxNativeEpoll(true);
config.useClusterServers().addNodeAddress("redis://127.0.0.1:6379");
RedissonClient redissonClient = Redisson.create(config);
RLock testLock = redissonClient.getLock("TEST_KEY");
testLock.lock();
testLock.lock();
问题一
java.lang.ClassNotFoundException: io.netty.channel.epoll.EpollEventLoopGroup
在 github 搜到 issues: https://github.com/redisson/r...
根据提示引入指定包后出现新问题
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>4.0.40.Final</version>
</dependency>
问题二
Caused by: java.lang.IllegalstateException: Only supported on Linux
at io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:267)
at io.netty.channel.epoll.Native.<clinit>(Native.java:64)
又尝试引入 netty-all 还是一样的错
<!-- https://mvnrepository.COM/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.5.Final</version>
</dependency>
解决方案
凝视代码时发现了这句:config.setUseLinuxNativeEpoll(true);
好像跟错误有关, 尝试着去除 netty 所有依赖后运行, 问题解决
总结
不要太相信官方的示例代码直接 copy , 要搞懂每句代码的含义。
以上是脚本宝典为你收集整理的使用 redisson 时遇到的问题全部内容,希望文章能够帮你解决使用 redisson 时遇到的问题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。