当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

S2SH整合之session

发表于: 2012-11-17   作者:灵静志远   来源:转载   浏览:
摘要: 错误信息: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cartService': Scope 'session' is not active for the current thread; consider defining a scoped
错误信息:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cartService': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:537)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:289)
... 40 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:122)
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:88)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
... 48 more


JAVA Code:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:ssh-*.xml</param-value>
  </context-param>

  <listener>
  <listener-class>
  org.springframework.web.context.ContextLoaderListener
  </listener-class>
  </listener>
   
  <listener>
  <listener-class>
  org.springframework.web.context.request.RequestContextListener
  </listener-class>
  </listener>
 
  <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
 
  <welcome-file-list>
    <welcome-file>main/main.jsp</welcome-file>
  </welcome-file-list>
</web-app>


ssh-service.xml

<bean id="cartService" scope="session" class="com.tarena.dang.service.impl.CartServiceImpl">
  <property name="proDao" ref="proDao" />
</bean>

到网上搜集答案:首先说web.xml里顺序有严格的要求,好吧!改改顺序,好在当年排列组合学得不错,把上面可能的出现的顺序一一试过。汗……问题照旧。
然后又有人说把listener换成filter。行吧,换!问题照旧。
后来终于解决:在ssh-service.xml的里加点东西
首先是beans里:
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation= 里面再添加:
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

然后:
<bean id="cartService" scope="session" class="com.tarena.dang.service.impl.CartServiceImpl">
  <property name="proDao" ref="proDao" />
  <aop:scoped-proxy/>
</bean>

S2SH整合之session

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
Struts2、Spring、Hibernate三大框架在一个项目中的具体职责分配如下: 三大框架整合,导入各个框架
添加struts2 的jar包:在源文件中有个example中的blank项目中的默认jar包 加入spring支持jar包: 添
首先加入Struts2.14的JAR包, 再是HibernateJAR包 然后再是SpringJAR包 ,由于是用idea开发,有些其
我使用的是myeclipse 10.0 整合的 一\添加spring支持 1.项目-->右键-->myeclipse-->选择Ad
我使用的是myeclipse 10.0 整合的 一\添加spring支持 1.项目-->右键-->myeclipse-->选择Ad
原创整理不易,转载请注明出处:java S2SH项目框架整合搭建实例教程 代码下载地址:http://www.zuid
S2SH:struts2+spring+hibernate,三个框架整合在一起。 首先,为项目增加struts2框架: 1、首先需
接着之前的一篇文章“框架技术--S2SH框架整合(使用myeclipse自动生成)”,这里我使用了注解搭建了
原创整理不易,转载请注明出处:java S2SH项目框架整合搭建实例教程 代码下载地址:http://www.zuid
前言:这里仅介绍memcached 的 session 共享方法 准备:由于还是得在windows平台下做这个演示,所以
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号