また、現在受け入れられている回答に1000票を投じることができればと思います。私はしばらくの間、これを行う方法に困惑していました。これに基づいて、Spring 3.0で新しい@Asyncのものを使用したい場合に備えて、Callableインターフェースを使用した私のソリューションを次に示します。
public abstract class RequestContextAwareCallable<V> implements Callable<V> {
private final RequestAttributes requestAttributes;
private Thread thread;
public RequestContextAwareCallable() {
this.requestAttributes = RequestContextHolder.getRequestAttributes();
this.thread = Thread.currentThread();
}
public V call() throws Exception {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
return onCall();
} finally {
if (Thread.currentThread() != thread) {
RequestContextHolder.resetRequestAttributes();
}
thread = null;
}
}
public abstract V onCall() throws Exception;
}