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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM