I just saw your question. I'm facing the exact same issue and I came up with the following solution, which probably it's not the best but at the moment it's enough for my tasks.
I have taken the idea here How to enable request scope in async task executor and I have slightly modified it because it wasn't working correctly for my needs.
What I did was:
- create a TenantAwareThreadPoolExecutor like the link above;
- create TenantAwareCallable (it will have a private String tenantName instead of the RequestAttributes (take it in the way you already do)).
- Create a singleton component which will store the current tenant which you got from the request.
- Save and clear into this component the tenant you need to use in the call() method of the callable.
- Now you must change your CurrentTenantIdentifierResolver to get the tenant from that singleton (after having checked the request, otherwise other requests will use the same tenant as that one).
Please note: this will work ONLY if you execute the tasks one after another in a queue style. If you execute some concurrently this approach will not work.
Any ideas for improvements will be accepted.