I used AbstractRoutingDataSource with great success , but I raised a problem that I can’t solve: when I start the asynchronous method with @Async, it loses the local thread context and I can’t determine where to set the database context switch. I usually do this in aspect or in HandlerInterceptor, but @Asyncnone of these regular routes go through. Is there an interceptor or something similar that I can configure to run at the beginning and end of an asynchronous call so that I can set the database context?
Found a similar question on Spring bulletin boards. No answer: http://forum.springsource.org/showthread.php?83792-Async-annotated-method-hanging-on-session-scoped-bean
EDIT: I debugged the execution thread, and the source AbstractRoutingData - actually receiving a call in the async thread, but its call is called before the aspect becomes callable, therefore it is DataSourcealready set in the Hibernate session before , the value is ThreadLocalset. Considering the source code for AsyncExecutionInterceptorthat supports @Asyncit, because the interceptor returns a value Orderlike HIGHEST_PRECEDENCE, therefore, its dismissal before anything else.
