给Spring 集成Ehcache
1.Srping主配置文件
xmlns:cache="http://www.springframework.org/schema/cache"
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
<!-- 缓存配置 -->
<!-- 启用缓存注解功能(请将其配置在Spring主配置文件中) -->
<cache:annotation-driven proxy-target-class="true" cache-manager="cacheManager"/>
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
<!-- 缓存页面需要de -->
<property name="shared" value="true"></property>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
2.POM
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.17.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.2.2.21</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-web</artifactId>
<version>2.0.4</version>
</dependency>
3.cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
<!--默认缓存 -->
<defaultCache eternal="false"
maxElementsInMemory="10000"
overflowToDisk="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
memoryStoreEvictionPolicy="LFU"/>
<!-- 自定义缓存 -->
<cache name="myCache"
eternal="false"
maxElementsInMemory="10000"
overflowToDisk="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
memoryStoreEvictionPolicy="LFU"/>
<!-- 页面缓存 -->
<cache name="SimplePageCachingFilter"
maxElementsInMemory="10"
maxElementsOnDisk="10"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="120"
timeToLiveSeconds="60"
memoryStoreEvictionPolicy="LFU">
</cache>
<!-- 页面局部缓存 -->
<cache name="SimplePageFragmentCachingFilter"
maxElementsInMemory="10"
maxElementsOnDisk="10"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="120"
timeToLiveSeconds="60"
memoryStoreEvictionPolicy="LFU">
</cache>
</ehcache>
4.web.xml 配置页面缓存
<!--ehcache 页面缓存过滤器
-->
<filter>
<filter-name>PageCacheFilter</filter-name>
<filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter</filter-class>
<init-param>
<param-name>cacheName</param-name>
<param-value>SimplePageCachingFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PageCacheFilter</filter-name>
<url-pattern>/common/index</url-pattern>
</filter-mapping>
<!--ehcache 页面局部缓存
<filter>
<filter-name>PageFragmentCachingFilter</filter-name>
<filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter</filter-class>
<init-param>
<param-name>cacheName</param-name>
<param-value>SimplePageFragmentCachingFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PageFragmentCachingFilter</filter-name>
<url-pattern>/WEB-INF/pages/testCache.jsp</url-pattern>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
-->
分享到:
相关推荐
spring集成ehcache所需的jar包
基于公司的项目在Spring中集成Ehcache,并提供EhcaheUtils工具类,并通过Spring的AOP编程实现方法缓存注解话,先奉献出核心代码,需要的朋友可以参考哦!
ssh,struts+hibernate+spring+ehcache集成
spring3整合EhCache注解实例
开源测试项目:spring mvc+springsecurity3+ehcache+bootstrap+mysql 内附MySQL表,直接导入就可运行 效果图请移步:http://blog.csdn.net/yangxuan0261/article/details/10053947
NULL 博文链接:https://cczakai.iteye.com/blog/1622708
spring集成ehcache简单示例
1.通过google ehcache-spring-annotatios.jar自动注解方式实现整合Spring+Ehcache。 2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。...
使用springboot 集成ehcache,里面附带数据库建库脚本,controller,service以及对ehcache集成,操作的详细样例,使用spring注解形式。
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2294952
项目简介:此项目只是简单的集成spring+springmvc+shiro+ehcahce 二: 步骤说明: 1:项目集成spring 在web.xml中配置spring容器的监听器。 2:项目集成springmvc 在web.xml中配置前端控制器 3:项目集成...
spring boot 集成activemq Datajpa Ehcache 里面有详细的例子
本篇文章主要介绍了详解spring boot集成ehcache 2.x 用于hibernate二级缓存,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
在本篇文章里小编给大家整理的是关于Spring Boot集成Ehcache缓存解决方式,需要的朋友们可以学习下。
本篇文章主要介绍了详解Spring MVC 集成EHCache缓存,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
在Spring+Hibernate集成环境中使用EhCache缓存做的开发测试,在线程中打开数据库查询数据,及关闭数据库后查询数据的结果.
SpringBoo2.x整合Ehcache3.x作为缓存底层存储。
Spring4MVC+Hibernate4+Freemarker+Ehcache+EasyUi整合,里面包含数据库,数据库使用的是Mysql
使用Intellj IDEA 集成开发工具 搭建的maven项目,使用Spring+Hibernate+Shiro+Ehcache集成,完成一个简单的用户角色菜单项目
Jersey , EHCache, Spring dao