zoukankan      html  css  js  c++  java
  • 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;
            }
        
    }
  • 相关阅读:
    .NET Core log4net 使用(转贴)
    Tomcat的工作原理
    Servlet工作原理
    java实现快速排序
    正则表达式积累
    js常用知识真理
    最常用的的设计模式
    【设计模式】单例设计模式
    java中堆栈区别,递归和迭代区别
    Struts2的工作原理
  • 原文地址:https://www.cnblogs.com/nanahome/p/7788453.html
Copyright © 2011-2022 走看看