Announcement Announcement Module
No announcement yet.
Request Scope for beans to be used in springsecurity Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request Scope for beans to be used in springsecurity

    My project is in spring mvc
    I am using request scope for beans. This beans work fine in spring mvc but when i call same beans in my spring security module using @qualifier then it gives me an error saying request scope is not defined

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean': 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; 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.
    MyBean is used to query database and hence it is used in my security module (spring security ) as well as in spring mvc

    What is the solution for it

    Any help will be highly appreciated

    Thanks and Regards
    Patil Abhijeet

  • #2
    This is likely a problem with where the request scope is defined. Keep in mind that while beans in the DispatcherServlet can see the beans from ContextLoaderListener, beans defined by ther ContextLoaderListener cannot see the beans in the DispatcherServlet's definitions.


    • #3
      so you mean we cannot use beans that are been marked as requestscope in spring mvc and spring security simultaneously even though we are using web application??


      • #4
        I'm saying that you should look and see where you defined the scope definition. If it is in your DispatcherServlet's ApplicationContext it will not work for beans defined by the ContextLoaderListener. Instead you will need to move the definitions to the same file.


        • #5
          My security definitions lie in the same file as my applicationContext in here it is spring-servlet.xml

          so what can I do to use the beans which are present in applicationContext into spring security?

          Also can you shed some light on what type of scopes are present in spring security ???