Results 1 to 3 of 3

Thread: request scoped providers with @Async

  1. #1
    Join Date
    Oct 2007
    Posts
    10

    Default request scoped providers with @Async

    Hi,

    i need to put facebook media upload action onto a separate thread (so the request returns immediatly) however when I do, I get an issue saying "Scope 'request' is not active for the current thread......" when I try & access the Facebook bean & looking at SPR-6873 I understand. what would the best approach for me to execute the media upload process in a separate thread....


    Thanks,

    Ian.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    Best approach? I might have to think more on that, but here's something that might work (a quick experiment on my end worked fine):

    I'm guessing that you're getting that exception because you're trying to inject the Facebook bean into the class that has the @Async method. Then when you try to use it, there's not live request and so Spring can't create the instance of the Facebook bean (using the access token for the current user, which is only known at request time).

    But what if you passed the already-created (at request time) instance to the @Async method that you're calling? For example:

    Code:
    myAsyncMethod(facebook.mediaOperations(), other, parameters);
    Then in myAsyncMethod() you can do whatever you need with the MediaOperations that was passed in.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Oct 2007
    Posts
    10

    Default

    Worked a treat - thanks Craig..

Posting Permissions

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