关于Scope 'session' is not active for the current thread的问题
来源:互联网 发布:博途v13编程手册 编辑:程序博客网 时间:2024/05/17 07:50
最近在做毕业设计,已近完成,却发现重大bug。
【问题概述】:我做的是订餐系统,测试时发现不用A客户可以看到B客户购物车中的餐品。由于我以前做过的类似的系统是没有用spring整合的,购物车这里可以与session绑定解决这个问题,如今使用spring整合却忽略了这个问题(好久没写代码了),如下本文就该问题给出解决方案,方案均来自互联网并非本人自己想到的,遂记下学习之。
【解决方法】:
造成这个问题的原因是spring默认所有的bean都为单例模式(scope="singleton"),固A,B客户操作的其实是同一个购物车实例。想要解决这个问题就需要将生命周期设置为session,即将Scope设置为scope="session",表示为一个session只创建一个实例。
将Scope设置为scope="session"需要在web.xml中做如下配置:
<!-- 开启Session机制 -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
此外还需要在spring配置文件中.相应的spring bean配置中加入<aop:scoped-proxy/>
<bean id="cartService" class="com.lvsl.bysj.service.impl.CartServiceImpl" scope="session">
<aop:scoped-proxy/>
<property name="cartDao" ref="cartDao"></property>
</bean>
- 关于Scope 'session' is not active for the current thread的问题
- Scope 'session' is not active for the current thread
- Scope 'request' is not active for the current thread
- org.springframework.beans.factory.BeanCreationException: Scope 'request' is not active for the current thread
- 解决Scope 'request' is not active for the current thread异常
- spring4+hibernate4+junit整合问题 Could not obtain transaction-synchronized Session for current thread的问题
- 关于在Spring中Hibernate的No Session found for current thread问题
- org.springframework.beans.factory.BeanCreationException: Scope 'request' is not active for the curre
- 关于Hibernate Could not obtain transaction-synchronized Session for current thread
- spring+hibernate Could not obtain transaction-synchronized Session for current thread问题总结
- 【Hibernate】Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- HibernateException: Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- java打印工具类
- python中格式化命令行参数——使用optparse处理命令行参数
- 一道淘汰85%面试者的百度开发者面试题
- GitHub详细教程
- OpenCV连续图片读取问题
- 关于Scope 'session' is not active for the current thread的问题
- maven基本用法
- Ref_Out
- opencv2使用形态学滤波对图像进行边缘及角点检测
- vimperator使用帮助
- ate
- python--切片
- t5e
- 鸟的很多地方非常值得老中们学习,尤其职场上斗阿三