spring缓存问题
来源:互联网 发布:cnc程序模拟软件 编辑:程序博客网 时间:2024/06/05 10:32
今天在使用分页进行查询的时候,出现一个问题:每次我选中特定的条件进行查询,当我重新点击struts的action时,按道理,是应该重新回到最初的没有选择任何查询条件的页面,但不管我怎么点击,重新发起请求,每次的结果都是按刚开始的查询条件查询出来的结果。
因为使用的Spring + mybatis + struts的框架,经同事指点,发现spring配置文件的,相应的action配置如下:
<bean id="AlarmInfoAction" class="com.cstor.network.alarm.action.AlarmInfoAction" >
<property name="alarmInfoService" ref="alarmInfoServiceImpl"/>
</bean>
添加上scope范围之后,问题圆满解决:
<bean id="AlarmInfoAction" class="com.cstor.network.alarm.action.AlarmInfoAction"scope="prototype">
<property name="alarmInfoService" ref="alarmInfoServiceImpl"/>
</bean>
对于spring的prototype范围,Spring官方文档对prototype的解释如下:
The prototype scope
The non-singleton, prototype scope of bean deployment results in thecreation of a new bean instance every time a request for that specific bean is made. That is, the bean is injected into another bean or you request it through a getBean()method call on the container. As a rule, use the prototype scope for all stateful beans and the singleton scope for stateless beans.The following diagram illustrates the Spring prototype scope.A data access object (DAO) is not typically configured as a prototype, because a typical DAO does not hold any conversational state; it was just easier for this author to reuse the core of the singleton diagram.
The following example defines a bean as a prototype in XML:
<!-- using spring-beans-2.0.dtd --><bean id="accountService" class="com.foo.DefaultAccountService" scope="prototype"/>
In contrast to the other scopes, Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, and otherwise assembles a prototype object, and hands it to the client, with no further record of that prototype instance. Thus, althoughinitialization lifecycle callback methods are called on all objects regardless of scope, in the case of prototypes, configureddestructionlifecycle
callbacks arenotcalled. The client code must clean up prototype-scoped objects and release expensive resources that the prototype bean(s) are holding. To get the Spring container to release resources held by prototype-scoped beans, try using a custombeanpost-processor, which holds a reference to beans that
need to be cleaned up. In some respects, the Spring container's role in regard to a prototype-scoped bean is a replacement for the Javanewoperator. All lifecycle management past that point must be handled by the client. (For details on
the lifecycle of a bean in the Spring container, see the section called “Lifecycle callbacks”.)
scope="prototype"(多态)是在每次用户发起请求时重新生成action对象,对于多线程访问不会出现问题,如果没有配置scope=prototype则添加的时候不会新建一个action,他任然会保留上次访问的过记录的信息。
默认是scope="singleton"(单态),这些bean被spring初始化后,始终只有一份,很适用于无状态的bean,DAO、Service都采用的这种。当然,scope的值还有session,request等等。
- spring缓存问题
- Spring Hibernate sqlquery 查询结果 缓存问题
- spring security 大用户量缓存问题
- 基于spring的rmi缓存问题
- Spring缓存池组件冲突问题
- spring+mybatis缓存的问题及源码
- Spring cloud config server 缓存问题
- spring缓存
- spring 缓存
- spring 缓存
- spring缓存
- Spring 缓存
- Spring 缓存
- Spring缓存
- spring缓存
- Spring对iBatis封装导致的缓存问题
- 项目开发中的缓存问题(hibernate+spring)
- jpa+spring jdbc混合作战引发的缓存问题
- android下小文件上传
- jqGrid基础学习:2第一个jqGrid
- Android开发 摄像头自动聚焦完美实现 --------------续上
- hdu 1878 欧拉回路
- ios程序内实现打电话
- spring缓存问题
- C#中的值类型与引用类型
- 人人都是产品经理 总结
- 正则表达式验证邮箱
- 企业网站SEO之外部优化建设建议
- ubuntu 11.04下android开发环境的搭建!
- 存储相关术语
- Java中Vector和ArrayList的区别
- 代码调用存储过程超时,SQL Server Management Studio里运行很快