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;
        }
    
}

 

转载于:https://www.cnblogs.com/nanahome/p/7788453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值