Autowiring HttpServletRequest in Spring controller
if it works that means spring doesn't inject exactly http request but a proxy. the proxy delegates calls to current http request
When a spring web based application bootstraps, it will register the bean of type ServletRequest
,ServletResponse
,HttpSession
,WebRequest
with the support of ThreadLocal variables. So whenever you request one kind of above four, the actual value will be the actual stored ThreadLocal variable that are bound to the current thread.
You can find the details implementation mechanisms of @Autowired HttpServletRequest at @Autowired HttpServletRequest
You can get HttpServletRequest
object in each webservice method. Such as:
@RequestMapping("/method")
public void method(HttpServletRequest req) {
// ...
}