springboot使用1.5.9.RELEASE
curator使用2.12.0
原代码:
package com.test.domi.controller;
import com.test.domi.common.utils.lock.ZKlock;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
@RestController
@RequestMapping("/zk")
public class ZKController {
@Autowired
private CuratorFramework zkClient;
private String lockPath = "/test";
@Autowired
private ZKlock zklock;
private int k = 1;
@GetMapping("/lock")
public Boolean getLock() throws Exception{
for (int i = 0; i < 20; i++) {
new Thread(new Runnable() {
@Override
public void run() {
InterProcessMutex lock = new InterProcessMutex(zkClient,lockPath);
try {
if (lock.acquire(10,TimeUnit.HOURS)) {
System.out.println(Thread.currentThread().getName() + "获得了分布式锁");
System.out.println("k================>" + k++);
Thread.sleep(5000);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
lock.release();
} catch (Exception e) {
e.printStackTrace();
}
}
// zklock.lock();
}
}).start();
}
return true;
}
}
测试zk的分布式锁出现以下异常:
InterProcessMutex lock = new InterProcessMutex(zkClient,lockPath);这一行报错:
java.lang.NoClassDefFoundError: org/apache/curator/shaded/com/google/common/collect/Maps
求大神解答!!!