org.apache.shiro.session.UnknownSessionException: There is no session with

<bean id="sessionDAO"
class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO">
<property name="cacheManager" ref="shiroCacheManager" />
</bean>
<bean id="shiroCacheManager" class="net.cache.redis.RedisCacheManager" />

 

想跟换Shiro中缓存系统,试了很多方法,一直报错 org.apache.shiro.session.UnknownSessionException: There is no session with 

要实现自己的Redis缓存,还是使用自带的EnterpriseCacheSessionDAO,只要把它需要的 cacheManager 换成自己的redis cache 实现就可以了。测试启动后没有再出现 no session 问题了

 

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import javax.annotation.Resource;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RedisCacheManager implements CacheManager{
    
     private static final Logger logger = LoggerFactory.getLogger(RedisCacheManager.class);

        // fast lookup by name map
        private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();

        @Resource
        private RedisDao redisDao;

        public <K, V> Cache<K, V> getCache(String name) throws CacheException {
            logger.debug("获取名称为: " + name + " 的RedisCache实例");
            Cache<K, V> c = caches.get(name);
            if (c == null) {
                c = new RedisCache<K, V>(redisDao);
                caches.put(name, c);
            }
            return c;
        }
    
}

 

posted @ 2017-11-05 19:59  nanahome  阅读(2465)  评论(0编辑  收藏  举报