Shiro教程(四)Shiro + Redis配置

JSON 2016-08-26 01:36:56 22324

shiro demo下载

Shiro + SSM(框架) + Freemarker(jsp)讲解的权限控制Demo,还不赶快去下载?




我们知道Shiro 提供了一系列让我们自己实现的接口,包括org.apache.shiro.cache.CacheManager org.apache.shiro.cache.Cache  等接口。那么我们要对这些做实现,就实现了 Shiro  Session  和用户认证信息、用户缓存信息等的缓存,存储。我们可以用缓存,如 Redis  memcache  EHCache  等,甚至我们可以用数据库,如 Oracle  Mysql  等,都可以,只有效率的快慢问题,功能都可以达到, Redis  有一个更实用的功能,就是ttl功能,我们这时候又想到一个 Nosql  --> Elasticsearch  也是带ttl功能的,那么也可以用它来实现。

那么我的教程是采用了 Redis  ,而且是用了Jedis Jedis 可以实现pool hash 的集群Redis

在我的教程里命名为spring-cache.xml ,配置如下:

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
	default-lazy-init="false">
		
	 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxActive" value="500"/><!-- 最大连接数 -->
        <property name="maxIdle" value="100"/><!-- 最大闲置 -->
        <property name="minIdle" value="10"/><!-- 最小闲置 -->
        <property name="maxWait" value="5000"/><!-- 最大等待 -->
        <property name="testOnBorrow" value="true"/><!-- 可以获取 -->
    </bean>

    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg index="0" ref="jedisPoolConfig"/>
        <constructor-arg index="2" value="6379"/><!-- 端口 -->
        <constructor-arg index="3" value="5000"/><!-- 超时 -->
        <constructor-arg index="1" value="127.0.0.1"/><!--Redis IP地址 -->
    </bean>
	
</beans>

如果 Redis  设置了密码,需要这样配置:

<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
	<constructor-arg index="0" ref="jedisPoolConfig"/>
    <constructor-arg index="2" value="6379"/><!-- 端口 -->
    <constructor-arg index="3" value="5000"/><!-- 超时 -->
    <constructor-arg index="1" value="127.0.0.1"/><!--Redis IP地址 -->
    <constructor-arg index="4" value="Redis-pswd"/><!--密码 -->
</bean>

对应的构造方法:

    public JedisPool(final Config poolConfig, final String host, int port,
            int timeout, final String password) {
        this(poolConfig, host, port, timeout, password, Protocol.DEFAULT_DATABASE);
    }

那么 Shiro  中的 Redis  配置已经配置好了,关于 Shiro  + Redis  配置请看下一篇博客,会详细讲到,原因是我觉得和下一篇和 Spring  的配置文件一起讲会关联性更好一点。

ps:都凌晨2 点了。^_^ 我要睡觉了。

有问题加群沟通。

版权所属:SO JSON在线解析

原文地址:https://www.sojson.com/blog/132.html

转载时必须以链接形式注明原始出处及本声明。

本文主题:

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

关于作者
一个低调而闷骚的男人。
相关文章
Shiro教程(六)Shiro整体的配置文件
Shiro教程Shiro 配置文件详细解释,Shiro自定义Filter配置
Shiro教程(十)Shiro 权限动态加载与配置精细讲解
Shiro教程(五)Shiro + Redis实现
Shiro教程(三)Shiro web.xml中Filter配置配置注意事项
Shiro教程(七)Shiro Session共享配置以及实现
Shiro教程(八)Shiro Freemarker标签的使用。
Shiro 教程Shiro教程0.2 下载,Shiro功能修复与升级说明。
Shiro 通过配置Cookie 解决多个二级域名的单点登录问题。
Shiro教程(九)Shiro JSP标签的使用。
最新文章
PHP变量剖析 4
SQL全外连接剖析 119
SQL自然连接剖析 147
springboot启动原理 245
SQL右连接【RIGHT JOIN】详解及图解 450
SQL左链接【LEFT JOIN】详解及图解 357
SQL非等值连接剖析 262
SQL等链接剖析 291
SQL内连接详解及图解 385
python之numpy常用的100种数值相关方法及代码示例 231
最热文章
最新MyEclipse8.5注册码,有效期到2020年 (已经更新) 679222
苹果电脑Mac怎么恢复出厂系统?苹果系统怎么重装系统? 674561
免费天气API,全国天气 JSON API接口,可以获取五天的天气预报 599008
免费天气API,天气JSON API,不限次数获取十五天的天气预报 565182
Jackson 时间格式化,时间注解 @JsonFormat 用法、时差问题说明 551699
我为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比 509186
Elasticsearch教程(四) elasticsearch head 插件安装和使用 479635
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ... 262798
Java 信任所有SSL证书,HTTPS请求抛错,忽略证书请求完美解决 244092
Elasticsearch教程(一),全程直播(小白级别) 225115
支付扫码

所有赞助/开支都讲公开明细,用于网站维护:赞助名单查看

查看我的收藏

正在加载... ...