Results 1 to 3 of 3

Thread: Autowiring session-scoped bean

Threaded View

  1. #1

    Question Autowiring session-scoped bean

    I'm having difficulties with a new session-scoped bean I've created, userPreferences. I get the following lengthy exception when I try to autowire it one of my Controllers:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'welcomeController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: com.foo.web.UserPreferences com.foo.web.WelcomeController.userPreferences; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userPreferences': 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.
    I've defined the userPreferences bean as follows:

    Code:
    @Component
    @Scope("session")
    public class UserPreferences {
      ...
    }
    And I autowired it into my Controller as follows

    Code:
    @Controller
    public class WelcomeController {
    
       @Autowired
       UserPreferences userPreferences;
    
    }
    I configured my dispatcherServlet.xml with the following to recognize annotations:

    Code:
    <context:annotation-config />
    <context:component-scan base-package="com.foo.web"/>
    Any ideas what I'm missing?
    Last edited by mark_m; Jan 6th, 2009 at 10:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •