All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.wzc789376152.shiro.config.ShiroRedisConfiguration Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
package com.github.wzc789376152.shiro.config;

import com.github.wzc789376152.shiro.properties.ShiroRedisProperty;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.crazycake.shiro.RedisCacheManager;
import org.crazycake.shiro.RedisManager;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "spring.shiro.redis", name = "enable", havingValue = "true")
@EnableConfigurationProperties(ShiroRedisProperty.class)
public class ShiroRedisConfiguration {
    @Autowired
    private RedisProperties redisProperties;

    /**
     * cacheManager 缓存 redis实现
     * 

* 使用的是shiro-redis开源插件 * * @return CacheManager */ @Bean("shiroRedisCacheManager") public CacheManager cacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(); redisCacheManager.setRedisManager(redisManager()); return redisCacheManager; } /** * RedisSessionDAO shiro sessionDao层的实现 通过redis *

* 使用的是shiro-redis开源插件 * @return SessionDAO */ @Bean public SessionDAO redisSessionDAO() { RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); redisSessionDAO.setRedisManager(redisManager()); return redisSessionDAO; } /** * 配置shiro redisManager *

* 使用的是shiro-redis开源插件 * * @return RedisManager */ @Bean public RedisManager redisManager() { RedisManager redisManager = new RedisManager(); redisManager.setHost(redisProperties.getHost() + ":" + redisProperties.getPort()); redisManager.setPassword(redisProperties.getPassword()); redisManager.setDatabase(redisProperties.getDatabase()); redisManager.setTimeout(redisProperties.getTimeout() == null ? 1000 : (int) redisProperties.getTimeout().getSeconds()); return redisManager; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy