@Component
public class JedisUtil {
@Autowired
private JedisPool jedisPool;
private Jedis getResource(){
return jedisPool.getResource();
}
public byte[] set(byte[] key, byte[] value) {
Jedis jedis=getResource();
try {
jedis.set(key,value);
return value;
} finally {
jedis.close();
}
}
public void expire(byte[] key, int value) {
Jedis jedis=getResource();
try {
jedis.expire(key,value);
} finally {
jedis.close();
}
}
public byte[] get(byte[] key) {
Jedis jedis=getResource();
try {
return jedis.get(key);
} finally {
jedis.close();
}
}
public void del(byte[] key) {
Jedis jedis=getResource();
try {
jedis.del(key);
} finally {
jedis.close();
}
}
public Set<byte[]> keys(String shiro_session_perfix) {
Jedis jedis=getResource();
try {
return jedis.keys((shiro_session_perfix+"*").getBytes());
} finally {
jedis.close();
}
}
}public class RedisSessionDao extends AbstractSessionDAO {
private final String SHIRO_SESSION_PERFIX = "shiro-session";
@Autowired
private JedisUtil jedisUtil;Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.study.shiro.util.JedisUtil' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我也遇到过,我的解决方法是springboot项目启动时候,把 jedis连接池初始化为bean就可以了
我也遇到了,找了半天原因是因为@Component没有被扫描
在spring配置文件最前面加上这个:
<context:component-scan base-package="com.kl.shiro.util"/>
怎么解决的?老哥