Assume we have defined a controller class which has @Controller
annotation only.
Inside the class, we have defined private @Autowired HttpServletR
Both are ok.
@Autowired HttpServletRequest
and passing as a parameter are the same things.
Before passing HttpServletRequest
to invocation method responding to @RequestMapping
function, Spring stores the HttpServletRequest
into a ThreadLocal
type variable.
That ThreadLocal
variable is a thread-safe map that keeps HttpServletRequest
in the current thread context. The @Autowired HttpServletRequest
proxy bean gets the correct request from that ThreadLocal
variable.