Skip to content

Instantly share code, notes, and snippets.

@avshabanov
Last active August 29, 2015 14:25
Show Gist options
  • Save avshabanov/c8722435227f22310a96 to your computer and use it in GitHub Desktop.
Save avshabanov/c8722435227f22310a96 to your computer and use it in GitHub Desktop.
Example, how to propagate Spring MVC's request context into the new thread
import com.truward.brikar.common.executor.ThreadParametersBinder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
public final class RequestScopeThreadLocalBinder implements ThreadParametersBinder {
@Override
public Object getLocalObject() {
return RequestContextHolder.getRequestAttributes();
}
@Override
public void setLocalObject(Object tag) {
final RequestAttributes requestAttributes = (RequestAttributes) tag;
RequestContextHolder.setRequestAttributes(requestAttributes);
}
@Override
public void unsetLocalObject(Object tag) {
RequestContextHolder.resetRequestAttributes();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment