How does the DispatcherServlet
(or any other bean, supporting Spring MVC infrastructure), dynamically, resolve the signature of the handler method of the @Component
instance, and how does it know, what parameters/types are expected, in which order, in that method?
If I have a "@RequestMapping
-ed" handler method, in my @Controller
instance, defining any version of its signature:
public String f() {...}
public String f(Model model) {...}
public String f(HttpServletRequest, Model model) {...}
public String f(Model model, HttpServletRequest) {...}
public String f(SomeEntity se, Model model, HttpServletRequest, AnotherModel am) {...}
//so on..
would work fine, disregarding of parameter number, types, and order, which, eventually, are supplied with corresponding arguments, again - disregarding of their number, order and types.
There should be quite a work going underneath, to correctly instantiate expected arguments, pass them in a proper order, maybe even do some type-casting, if needed.. an so on, but I don't grasp the fundamentals of this.
I looked up the corresponding sources from spring-webmvc
module, and sources of the DispatcherServlet
; however, haven't got a firm grasp of the underlying mechanism.
I can guess, that some BeanPostProcessor
s could be involved.. doing reflective accesses, and so on.. but even in this case, as I'm not certain on what's happening, I would very much appreciate any valuable input.