For eg:
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
public class HttpRequestServiceImpl implements HttpRequestService{
@Autowired private HttpServletRequest httpServletRequest;
@Override
public String getAttribute(String name) {
return (String)this.httpServletRequest.getAttribute(name);
}
}
So when multiple requests come to this service, how is the correct httpServletRequest corresponding to the user request injected into this service object. The answer is that a real HttpServletRequest is not really injected, only a proxy is injected in. The proxy is internally a reference to RequestContextHolder which at some point binds the HttpServletRequest to a threadlocal variable.
This is the kind of clarification I was looking for: concise, clear and complete.
ReplyDeleteMany thanks!