Results 1 to 5 of 5

Thread: Request Scope for beans to be used in springsecurity

  1. #1
    Join Date
    Jun 2011
    Posts
    117

    Default 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

    Code:
    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
    In Rat race who ever wins or looses still remains the Rat.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    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.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3
    Join Date
    Jun 2011
    Posts
    117

    Default

    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??
    In Rat race who ever wins or looses still remains the Rat.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    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.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  5. #5
    Join Date
    Jun 2011
    Posts
    117

    Default

    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 ???
    In Rat race who ever wins or looses still remains the Rat.

Posting Permissions

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