Announcement Announcement Module
No announcement yet.
Autowiring session-scoped bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:; 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:

    public class UserPreferences {
    And I autowired it into my Controller as follows

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

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

  • #2
    Change your component-scan tag as follows:

    <context:component-scan base-package="" scoped-proxy="targetClass" />
    This will add a scope proxy as needed. You should make sure you have CGLIB in your classpath, since it is required.


    • #3
      Thank you. That resolved the issue.