Spring注解入门 scope为'request'错误有关问题

Spring注解入门 scope为'request'异常问题

Spring注解入门


更多相关推荐 这个问题花费了我几个小时,我已经在web.xml中添加了RequestContextListener监听器,而且在配置'KnowledgeService'这个bean中也使用scope为'request',但是不抛出异常。而在配置'UserService'这个bean时硬是抛出了下面这个异常:
Error creating bean with name 'UserService': Scope 'request' 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;

幸好,经过一翻苦战,终于明白其中的道理...

Scope 'request' is not active for the current thread这句话中说明在某个线程上试图调用scope为request的bean,但是这个bean中能被在http请求线程中实例化,简单地说就是:在客户请求的时候才可以被实例化。而我的问题是在服务器启动的时候要实例化,所以有"Scope 'request' is not active for the current thread"这一句的出现。在项目中如果有些bean实现了spring中的某些接口(如:SessionAware,RequestAware或BeanPostProcessor等等),就会在服务器启动的时候自动创建代理(proxy),这时如果该bean的scope为request、session...这些web作用域的时候就会出现consider defining a scoped proxy for this bean if you intend to refer to it from a singleton这句话。我的'UserService'这个bean就是间接实现了BeanPostProcessor这个接口,所以一直抛出上面的异常。
希望能对遇到这种情况的朋友有所帮助。

<listener>
     <listener-class>
       org.springframework.web.context.request.RequestContextListener
     </listener-class>
  </listener

org.springframework.web.servlet包为什么没有了?

Spring 2.5.5的spring.jar文件中不知为什么org.springframework.web.servlet包没有了,原来在Spring2.0.8下正常运行的程序现在都不能运行了,请问用什么办法解决呢?

采纳的答案
Spring MVC已经作为一个单独的了项目拿出来了, 发布时没有加到SpringFrameWork里面, 这部分在spring-webmvc.jar这个jar中, 你加到classpath就可以了!

--------------------------------------------
提问者对于答案的评价:
感谢小疯子的回答,问题已经解决。如果您能在回答中多说一句“在发行包的 lib/modules 目录中存在”就更好了。