Announcement Announcement Module
No announcement yet.
request scoped providers with @Async Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • request scoped providers with @Async


    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....



  • #2
    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:

    myAsyncMethod(facebook.mediaOperations(), other, parameters);
    Then in myAsyncMethod() you can do whatever you need with the MediaOperations that was passed in.


    • #3
      Worked a treat - thanks Craig..