spring+shiro+ehcache整合
1.导入jar包(pom.xml文件)
<!-- ehcache缓存框架 -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.11</version>
</dependency>
Spring 整合 ehcache 包 spring-context-support 包
2.使用 ehcache ,导入 ehcache.xml 配置文件
解压 ehcache-core.jar 包 ,将 ehcache-failsafe.xml 复制 src/main/resources
改名 ehcache.xml
ehcache.xml文件
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> <diskStore path="java.io.tmpdir"/>
<!-- 默认缓存区 -->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<!-- 自定义缓存区 -->
<cache name="bos"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</cache>
<!-- 自定义缓存区 -->
<cache name="standard"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</cache> </ehcache>
|
3.applicationContext-ehcache.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:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd "> <!-- 缓存配置 -->
<bean id="ehCacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean> <!-- shiro封装cacheManager -->
<bean id="shiroCacheManager"
class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManager" ref="ehCacheManager" />
</bean> <!-- spring 封装ehcache缓存管理器 -->
<bean id="springCacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehCacheManager" />
</bean> <!-- 激活spring 缓存注解 -->
<cache:annotation-driven cache-manager="springCacheManager"/> </beans>
加载该配置文件
4.修改web.xml文件
<!-- spring配置文件位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
5.将cache管理器注入到安全管理器中
6.对认证数据、授权数据 哪些进行缓存 ?
对应到ehcache.xml文件中的自定义的缓存缓存区
注意: 使需要缓存对象,实现 Serializable 接口
使用注解进行开发
第七步: 在被 spring 管理 bean 对象方法上 使用@Cacheable 、@CacheEvict
@Cacheable 应用缓存区,对方法返回结果进行缓存 ---- 用于查询方法
@CacheEvict 清除缓存区数据 --- 用于 增加、修改、删除 方法
spring+shiro+ehcache整合的更多相关文章
- Spring和EhCache整合(针对使用了Shiro)
https://blog.csdn.net/a243293719/article/details/78277895
- spring和ehcache整合,实现基于注解的缓存实现
要实现基于注解的缓存实现,要求Spring的版本在3.1或以上版本. 首先需要在spring的配置文件中添加对缓存注解的实现: <?xml version="1.0" enc ...
- Ehcache学习总结(2)--Ehcache整合spring配置
首先需要的maven依赖为: [html] view plain copy <!--ehcache--> <dependency> <groupId>com.goo ...
- Shiro【授权过滤器、与ehcache整合、验证码、记住我】
前言 本文主要讲解的知识点有以下: Shiro授权过滤器使用 Shiro缓存 与Ehcache整合 Shiro应用->实现验证码功能 记住我功能 一.授权过滤器测试 我们的授权过滤器使用的是pe ...
- 010-shiro与spring web项目整合【四】缓存Ehcache
一.Ehcache shiro每次授权都会通过realm获取权限信息,为了提高访问速度需要添加缓存,第一次从realm中读取权限数据,之后不再读取,这里Shiro和Ehcache整合. 1.添加Ehc ...
- Ehcache 整合Spring 使用页面、对象缓存
Ehcache 整合Spring 使用页面.对象缓存 Ehcache在很多项目中都出现过,用法也比较简单.一 般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布 ...
- (转)Ehcache 整合Spring 使用页面、对象缓存
Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...
- ehcache整合spring本地接口方式
一.简介 ehcache整合spring,可以通过使用echache的本地接口,从而达到定制的目的.在方法中根据业务逻辑进行判断,从缓存中获取数据或将数据保存到缓存.这样让程序变得更加灵活. 本例子使 ...
- Ehcache 整合Spring 使用页面、对象缓存(转载)
Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...
随机推荐
- vim常用操作和使用技巧
vi是linux与unix下的常用文本编辑器,其运行稳定,使用方便,本文将分两部分对其常用操作技巧和配置进行阐述,其中参考了网上的一些文章,对作者表示感谢 PART1 操作技巧 说明: 以下的例子中 ...
- CentOS7 YUM安装与配置 MySQL5.7
原文链接:http://blog.csdn.net/xyang81/article/details/51759200 安装环境:CentOS7 64位,MySQL5.7 1.配置YUM源 在MySQL ...
- hive的使用
1,前言 书接上回,接着对上一个hive安装后环境下的hive使用.
- 笔记:python (2015)
[开发环境]: Python 3.3 http://rj.baidu.com/soft/detail/25283.html 大小:20.2M 版本:3.3.5150 位数:64 更新日期:2014 ...
- python_10 迭代器和生成器
迭代器协议: 1.迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个Stopiteration异常,以终止迭代(只能往后走不能往前退) 2.可迭代对象:实现 ...
- 深入理解Java虚拟机之Java内存区域随笔
1.java内存区域与内存溢出异常 Java 虚拟机在执行 Java 程序的过程中会把它管理的内存划分成若干个不同的数据区域:1.程序计数器,2.栈(虚拟机栈和本地方法栈 ),3.堆,4.方法区(包含 ...
- postgres on linux red hat 7 配置问题
记录几个重点的东西吧,具体的步骤 不上了,网上有很多, 1. redhat subscripiton需要订阅,没钱的需要去更换yum 源,也很简单,就是把自带的yum给删掉,重装其他的,大家可以百度 ...
- centos7下面添加htop工具
htop下载wget http://sourceforge.net/projects/htop/files/latest/download 解压tar -zxf downloadcd htop-1.0 ...
- ASP.NET网站报Service Unavailable错误的解决办法
现象:网站打不开,提示 service unavailable 原因:IIS资源不足,程序占用资源太多,应用程序池会被自动禁用 解决办法:重启IIS,在命令行中输入iisreset即可
- PTA 1067 Sort with Swap(0, i) (25 分)(思维)
传送门:点我 Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasin ...