在项目中使用Maven+spring+redis,但是在运行服务器的时候报错:以下是我的配置文件
applicationContext-redis.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="50" /> <!--最大连接数-->
<property name="maxIdle" value="10" /> <!--最大空闲数-->
<property name="maxWaitMillis" value="1000" /> <!--最大等待时间ms-->
<property name="testOnBorrow" value="true" />
</bean>
<bean id="jedis.shardInfo" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="127.0.0.1" />
<constructor-arg index="1" value="6379" />
</bean>
<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
<constructor-arg index="0" ref="jedisPoolConfig" />
<constructor-arg index="1">
<list>
<ref bean="jedis.shardInfo" />
</list>
</constructor-arg>
</bean>
</beans>
redisServiceImpl.java:
package org.zh.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.zh.service.IRedisService;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
import javax.annotation.Resource;
/**
* Created by ZhaoHang on 2016/7/19.
*/
@Component
@Transactional(readOnly = true)
public class RedisServiceImpl implements IRedisService {
@Autowired
private ShardedJedisPool shardedJedisPool;
@Override
public void setValue(String key, String val) {
ShardedJedis jedis = null;
try{
jedis = shardedJedisPool.getResource();
jedis.set(key, val);
} catch (Exception e){
e.printStackTrace();
} finally{
if(jedis != null) jedis.close();
}
}
@Override
public String getValue(String key) {
ShardedJedis jedis = null;
jedis = shardedJedisPool.getResource();
return jedis.get(key);
}
}