It's the first time I try to use 'spring-data-redis', I got an unexcepting exception while I wrote a test application with spring-data-redis, the log messages were listed below. Can anyone help me to figure it out? Thansk first!
and here is the code:
Code:
java.lang.NoClassDefFoundError: org/springframework/data/redis/core/RedisConnectionUtils$RedisConnectionHolder
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:68)
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:53)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:150)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:133)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84)
at org.springframework.data.redis.core.DefaultListOperations.leftPush(DefaultListOperations.java:73)
at org.springframework.data.redis.core.DefaultBoundListOperations.leftPush(DefaultBoundListOperations.java:67)
at org.springframework.data.redis.support.collections.DefaultRedisList.addFirst(DefaultRedisList.java:301)
at org.springframework.data.redis.support.collections.DefaultRedisList.offerFirst(DefaultRedisList.java:333)
at com.kempsoft.test.FifoTest.enterTheFifo(FifoTest.java:44)
at com.kempsoft.test.FifoTest.test(FifoTest.java:59)
at com.kempsoft.test.FifoTest.main(FifoTest.java:101)
java.lang.NoClassDefFoundError: org/springframework/data/redis/core/RedisConnectionUtils$RedisConnectionHolder
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:68)
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:53)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:150)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:133)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84)
at org.springframework.data.redis.core.DefaultListOperations.leftPush(DefaultListOperations.java:73)
at org.springframework.data.redis.core.DefaultBoundListOperations.leftPush(DefaultBoundListOperations.java:67)
at org.springframework.data.redis.support.collections.DefaultRedisList.addFirst(DefaultRedisList.java:301)
at org.springframework.data.redis.support.collections.DefaultRedisList.offerFirst(DefaultRedisList.java:333)
at com.kempsoft.test.FifoTest.enterTheFifo(FifoTest.java:44)
at com.kempsoft.test.FifoTest.test(FifoTest.java:59)
at com.kempsoft.test.FifoTest.main(FifoTest.java:101)
Code:
package test;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.data.redis.support.collections.DefaultRedisList;
import org.springframework.data.redis.support.collections.RedisList;
@Named
public class FifoTest {
private final StringRedisTemplate template;
private RedisList<String> users;
@Inject
public FifoTest(StringRedisTemplate template) {
this.template = template;
users = new DefaultRedisList<String>("users", template);
}
public boolean enterTheFifo(String name) {
return users.offerFirst(name);
}
public Collection<String> listTheFifo(Range range) {
return users.range(range.being, range.end);
}
public String leaveTheFifo() {
return users.pollLast();
}
public void stressTest() {
while (true) {
try {
System.out.println("insert users...");
if (!enterTheFifo("kemp")) break;
if (!enterTheFifo("nancy")) break;
if (!enterTheFifo("joy")) break;
if (!enterTheFifo("jack chen")) break;
System.out.println("list all users...");
List<String> users = (List<String>) listTheFifo(new Range());
int count = users.size();
for (String user : users) {
System.out.println(user);
}
System.out.println("remove users...");
while (count-- > 0) {
System.out.println(leaveTheFifo());
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
break;
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext-redis.xml");
// For the destroy method to work.
ctx.registerShutdownHook();
// FifoTest fifoTest = new FifoTest();
FifoTest fifoTest = ctx.getBean(FifoTest.class);
fifoTest.stressTest();
}
}