为了使用 redis 的分布式可重入锁, 决定引入 redissonjava
<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... git
根据提示引入指定包后出现新问题github
<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 仍是同样的错redis
<!-- 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 , 要搞懂每句代码的含义。oop