NutzCN Logo
问答 springboot读取shiro缓存
发布于 2176天前 作者 xiaoqiu1235 2054 次浏览 复制 上一个帖子 下一个帖子
标签:

如何再springboot工程通过bean注入读取另外一个系统中用户的登录缓存信息呢

<dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutz-plugins-cache</artifactId>
            <version>1.r.66-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-ehcache</artifactId>
            <version>1.3.2</version>
        </dependency>

springboot中用的这个包

4 回复

好像跟nutz的cache没什么关系吧

登录session是缓存到ehcache中和redis中,所以我现在另一个系统中读取缓存判断登录

@Bean
    public LCacheManager cacheManager() {
        LCacheManager cacheManager = new LCacheManager();
        cacheManager.setJedisAgent(jedisAgent());
        cacheManager.setLevel1(ehCacheManager());
        cacheManager.setLevel2(redisCacheManager());
        return cacheManager;
    }

    @Bean
    public JedisAgent jedisAgent() {
        PropertiesProxy proxy = new PropertiesProxy();
        proxy.set("redis.mode", "normal");
        proxy.set("redis.host", "192.168.0.117");
        proxy.set("redis.database", "2");
        proxy.set("redis.port", "6379");
        proxy.set("redis.password", "hxcf9966");
        proxy.set("redis.timeout", "2000");

        JedisAgent jedisAgent = new JedisAgent();
        jedisAgent.setConf(proxy);
        return jedisAgent;
    }

    @Bean
    public RedisCacheManager redisCacheManager() {
        RedisCacheManager redisCacheManager = new RedisCacheManager();
        redisCacheManager.setDebug(true);
        redisCacheManager.setMode("kv");
        redisCacheManager.setTtl(1800);
        return redisCacheManager;
    }

    @Bean
    public EhCacheManager ehCacheManager() {
        EhCacheManager ehCacheManager = new EhCacheManager();
        ehCacheManager.setCacheManagerConfigFile("classpath:ehcache.xml");
        return ehCacheManager;
    }
@Autowired
    private LCacheManager cacheManager;

    @Test
    public void tests() throws Exception {
        Cache<String, Deque<Serializable>> cache = cacheManager.getCache("shiro-activeSessionCache");
//        String result = HttpUtil.post("http://192.168.0.33:8080/isLogin", "chUserId=18673196119", HttpUtil.CHARSET);
        cache.get("18673196219");

    }

这样试了下没用

看看有哪些key嘛,通常是session id做key的

redis中存储的是这个

shiro-activeSessionCache:18673196219
添加回复
请先登陆
回到顶部