- 浏览: 1526313 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (225)
- JAVA (27)
- Spring (49)
- Linux (51)
- JavaScript (8)
- Scrum (23)
- IDE (2)
- JSON (2)
- Solr (0)
- Webharvest (0)
- Hibernate (8)
- 杂谈 (3)
- Windows 7 (4)
- 持续集成 (23)
- tomcat (3)
- Android (1)
- SpringSecurity (11)
- Maven (9)
- jotm (3)
- C3P0 (1)
- Active Directory (2)
- cas (1)
- JQuery (2)
- ajax (1)
- plsql (2)
- nginx (4)
- apache (1)
- thrift (7)
- python (3)
- oracle (4)
- php (2)
- redis (1)
- fedora (1)
- windows7 (0)
- SVN (1)
- NFS (1)
- SAMBA (1)
- Atomikos (1)
- apache-poi (1)
- mysql (2)
- vncserver (1)
- mac (2)
- firefox (1)
- JIRA (1)
- p6spy (1)
- git (1)
- github (1)
- gitlab (1)
- gogs (1)
- Druid (1)
- MyBatis (1)
- docker (8)
- zabbix (1)
最新评论
-
lialatd:
您好,我用您的方法通过java api往jira系统中添加is ...
JIRA REST API ---- JAVA -
sprcen945:
可以了,是因为没加intercept-url 的拦截, 尼玛, ...
SpringSecurity3.X--Cas client 配置 -
sprcen945:
请问为什么我配了security.xml后切入点不起作用(之前 ...
SpringSecurity3.X--Cas client 配置 -
linxingyul:
根据楼主的代码 继承了WebMvcConfigurationS ...
SpringMVC4零配置--Web上下文配置【MvcConfig】 -
java_老头:
MvcConfig.java的FilterType.ANNOT ...
SpringMVC4零配置--Web上下文配置【MvcConfig】
关于Spring3.1 Cache注解的介绍请参看http://hanqunfeng.iteye.com/blog/1158824
这里只说一下遇到的问题,web应用,session超时为30分钟,使用Cache注解+EHCache,如下:
<cache name="andCache" maxElementsInMemory="10000" maxElementsOnDisk="1000" eternal="false" overflowToDisk="true" diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" /> 说明:缓存名andCache,内存中最多可缓存10000个Element,其中的element会在闲置5分钟或是存活10分钟之后失效, 超过10000element时,element将会输出到磁盘中。
结果,在登录系统后,如果超过5分钟不访问系统,则会出现异常,
按照这样配置,我原以为,如果5分钟之内不访问应用,则缓存会失效,那么spring就会重新执行原先被缓存的方法,但实际上,方法并没有被重新执行,而是返回了null,貌似spring依旧是从缓存中查找,并且找到了key,只不过value已经是null了。
这样就会导致系统出现空指针异常,况且session也尚未超时,
但就算是将闲置时间设置为30分钟以上,用户在下次登录时一样会出现异常,但是第二次登录就又会正常,然后周而复始,貌似,只有当第一次取到null后,spring才会重新执行方法。
感觉上,好像ehcache清除缓存后,spring并不知道,因为key依旧可以在spring的cache中找到,但是通过key取值时,spring会从ehcache中查找,由于ehcache已经清除了缓存,所以返回值一定是null,而spring也把这个null当成了被缓存的value返回给系统。
使用spring自带的缓存机制没有遇到该问题。
评论
5 楼
xiaoyaozjl
2013-04-08
LZ使用的是spring 3.1.0.M1版本,也就是里程碑版本非正式版,是存在这个问题的。在spring 3.1.0.M2里面已经修正了。
3.1.0.M1版本的org.springframework.cache.ehcache.EhCacheCache.java:
3.1.0.M2版本的org.springframework.cache.ehcache.EhCacheCache.java:
3.1.0.M1版本的org.springframework.cache.ehcache.EhCacheCache.java:
public Object get(Object key) { Element element = cache.get(key); return (element != null ? element.getObjectValue() : null); }
3.1.0.M2版本的org.springframework.cache.ehcache.EhCacheCache.java:
public ValueWrapper get(Object key) { Element element = cache.get(key); return (element != null ? new DefaultValueWrapper<Object>(element.getObjectValue()) : null); }
4 楼
yaofaye
2013-02-26
对的,返回的null是,key对应的value值为null,并不是Cache.ValueWrapper为null,客户端判断一下value值,如果为null,返回一个null的Cache.ValueWrapper即可。
从源码上看不应该是这样吧?
代理方法会拦截并判断Cache.ValueWrapper是否为空,如果为空直接invoke原方法,返回原方法中查询出来的对象
songbin0201 写道
引用
但实际上,方法并没有被重新执行,而是返回了null,貌似spring依旧是从缓存中查找,并且找到了key,只不过value已经是null了。
从源码上看不应该是这样吧?
代理方法会拦截并判断Cache.ValueWrapper是否为空,如果为空直接invoke原方法,返回原方法中查询出来的对象
// follow up with cacheable //inspectCacheables根据cachename验证Cache.ValueWrapper是否为空 CacheStatus status = inspectCacheables(ops.get(CACHEABLE)); Map<CacheOperationContext, Object> updates = inspectCacheUpdates(ops.get(UPDATE)); if (status != null) { if (status.updateRequired) { updates.putAll(status.cUpdates); } // return cached object else { return status.retVal; } } retVal = invoker.invoke();//retVal如果为空,直接调用原方法,返回非缓存数据
inspectCacheables方法中关于验证Cache.ValueWrapper的代码,为空设置localCacheHit 为false,localCacheHit为false,设置需要重新更新cache boolean localCacheHit = false; // check whether the cache needs to be inspected or not (the method will be invoked anyway) if (!updateRequire) { for (Cache cache : context.getCaches()) { Cache.ValueWrapper wrapper = cache.get(key); if (wrapper != null) { retVal = wrapper.get(); localCacheHit = true; break; } } } if (!localCacheHit) { updateRequire = true; }
3 楼
songbin0201
2012-12-17
引用
但实际上,方法并没有被重新执行,而是返回了null,貌似spring依旧是从缓存中查找,并且找到了key,只不过value已经是null了。
从源码上看不应该是这样吧?
代理方法会拦截并判断Cache.ValueWrapper是否为空,如果为空直接invoke原方法,返回原方法中查询出来的对象
// follow up with cacheable //inspectCacheables根据cachename验证Cache.ValueWrapper是否为空 CacheStatus status = inspectCacheables(ops.get(CACHEABLE)); Map<CacheOperationContext, Object> updates = inspectCacheUpdates(ops.get(UPDATE)); if (status != null) { if (status.updateRequired) { updates.putAll(status.cUpdates); } // return cached object else { return status.retVal; } } retVal = invoker.invoke();//retVal如果为空,直接调用原方法,返回非缓存数据
inspectCacheables方法中关于验证Cache.ValueWrapper的代码,为空设置localCacheHit 为false,localCacheHit为false,设置需要重新更新cache boolean localCacheHit = false; // check whether the cache needs to be inspected or not (the method will be invoked anyway) if (!updateRequire) { for (Cache cache : context.getCaches()) { Cache.ValueWrapper wrapper = cache.get(key); if (wrapper != null) { retVal = wrapper.get(); localCacheHit = true; break; } } } if (!localCacheHit) { updateRequire = true; }
2 楼
jahu
2012-12-15
登录用户,不用缓存吧,
1 楼
snowolf
2012-09-24
多个应用,分布式部署,缓存数据如何保持一致性?
发表评论
-
Druid学习笔记
2016-10-07 11:55 2445官方网站:https://github.com/aliba ... -
JIRA REST API ---- JAVA
2015-09-24 15:51 13269最近在搞自动化监控 ... -
Spring Cache注解+Redis
2015-01-15 13:36 54434Spring3.1 Cache注解 依赖jar包: ... -
Spring Cache注解+Memcached
2015-01-12 16:11 20393Spring3.1 Cache注解 依赖jar包: ... -
Spring4+Hibernate4+Atomikos3.3多数据源事务管理
2014-09-25 10:46 8336Spring3+后不再对JTOM提供支持,所以可以改用At ... -
SpringMVC4零配置--Web上下文配置【MvcConfig】
2014-09-10 18:22 73350与SpringSecurity的配置类似,spring同样 ... -
SpringMVC4零配置--SpringSecurity相关配置【SpringSecurityConfig】
2014-09-10 18:22 71916SpringSecurity的配置相对来说有些复杂,如果 ... -
SpringMVC4零配置--应用上下文配置【AppConfig】
2014-09-10 18:21 26473从spring3.0开始,Spring将JavaConfi ... -
SpringMVC4零配置--web.xml
2014-09-10 18:21 98634servlet3.0+规范后,允许servlet,filt ... -
SpringMVC4零配置
2014-09-05 19:11 89907基于Servlet3.0规范和SpringMVC4注解式配 ... -
SpringSecurity3.X--LDAP:AD配置
2014-07-08 17:08 5519前面介绍过基于本地数据库验证的方式,参考http://ha ... -
Thrift--JSClient
2013-09-26 14:45 5914thrift提供了基于jquery--ajax的客户端调用 ... -
Thrift--Spring集成ThriftServlet
2013-09-25 11:42 11080Thrift除了可以通过TCP协议访问,还可以通过HTTP ... -
Thrift转SpringHttpInvoker
2013-09-24 13:26 1728关于在spring中集成Thrift请参看:http://h ... -
Thrift--JavaServer&PythonClient遇到的问题
2013-09-23 10:16 1404thrift在java中的应用参考:http://hanqu ... -
Spring集成Thrift--Server AND Client
2013-09-04 20:13 13714Thrift网上有N多教程, ... -
Windows Server 2008 Active Directory 安装及使用笔记
2013-03-22 18:49 26361.安装AD http://www.docin.com/ ... -
C3P0配置实战
2012-09-04 18:34 51850C3P0: 一个开源的JDBC连接池,它实现了数据源和JN ... -
spring+jotm 多数据源事务管理(三)JNDI+Tomcat
2012-06-07 16:27 5221spring+jotm 多数据源事务管理系列 spr ... -
spring+jotm 多数据源事务管理(二)hibernate
2012-06-07 11:20 2814spring+jotm 多数据源事务管理系列 spr ...
相关推荐
开源测试项目:spring mvc+springsecurity3+ehcache+bootstrap+mysql 内附MySQL表,直接导入就可运行 效果图请移步:http://blog.csdn.net/yangxuan0261/article/details/10053947
积分最低,Spring MVC+Mybatis+Ehcache+Apache Shiro+Bootstrap整合开发java仓库管理系统源码 开发环境:Eclipse ,JDK 1.8 ,Tomcat7 技术选型 后端技术 SpringMVC MVC框架 Spring Framework 容器 Apache ...
自己项目的开发包集合,其中包括:缓存处理ehcache相关jar,spring MVC4.0 jar,ehcache依赖jar,以及其他jar(图像处理thumbnailator-0.4.2),包虽然不是很新但可用。实际使用时找包较为麻烦,现在整理出来,希望...
hibernate4+spring4+springmvc+ehcache+自己写的cache系统
spring + ehcache + redis两级缓存
spring+ehcache+mabatis。测试用例用的是mysql,数据库的配置在jdbc.properties里面。所要的sql在src/main/resources下的student.sql。测试的话调用controller下的update和getOne那两个接口测试。
Spring+EhCache实例源码,本实例的环境 eclipse + maven + spring + ehcache + junit,实例详解请访问博主博客:http://blog.csdn.net/u013142781
采用流行的框架springMvc+spring+mybatis+shiro+redis+ehcache开发,实现了权限管理(菜单权限、数据权限),solr全文搜索引擎,activiti工作流程引擎,cas单点登陆等功能,完善的代码生成器 后期还会考虑改造成模块...
1.通过google ehcache-spring-annotatios.jar自动注解方式实现整合Spring+Ehcache。 2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。...
spring+ibatis+ehcache整合完整例子,数据库MySQL
spring+ehcache示例整合Demo
使用spring boot 创建的一个 集成了hibernate+shiro+ehcache的项目 分享
以SpringBoot 为中心,模块化开发系统,用户可以随意删减除权限...复用,组装性强主要应用技术:spring Security+Ehcache+quartz+swagger2+Mysql5.6+springjdbc+druid+spring social+spring session + layerui+vue.js
自己整合的Spring+Hibernate+Ehcache 整合的项目 需要struts的自己添加。 里面带有注释,而且带Jar.写的很清楚,良心分。
SpringMVC+Mybatis+Spring+Shiro+ehcache整合配置文件
【B1】Spring+SpringMVC+Ehcache+Shiro+BootStrap企业级开发平台源码下载 内置功能 用户管理 角色管理 菜单管理 字典管理 部门管理 附件管理 参数管理 连接池监视 日志管理 技术选型 1、后端 核心框架...
maven环境下如何整合spring+hibernate+mysql+ehcache的方法
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等...基于Spring+JPA+Velocity+Ehcache开发的商城系统源码+数据库(结合URL重写技术静态化商城前台页面).zip