Last active
August 29, 2015 14:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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