I am beginner in Spring MVC. I didn't understand handler adapters clearly. What is a handler adapter and when do I use adapters?
Handler is a inclusive i.e. covering all the services details. Controller is an an exclusive implementation.
HandlerMapping is an interface that defines a mapping between requests and handler objects. While Spring MVC framework provides some ready-made implementations, the interface can be implemented by developers to provide customized mapping strategy.
Class HandlerMethod. Encapsulates information about a handler method consisting of a method and a bean. Provides convenient access to method parameters, the method return value, method annotations, etc. The class may be created with a bean instance or with a bean name (e.g. lazy-init bean, prototype bean).
The handler method returns a Boolean value. This value indicates whether Dynamo should continue processing the rest of the page after this handler has finished. If false is returned, Dynamo does not process any remaining values after calling the handler, nor serves the rest of the page.
A HandlerMapping
maps a method to a URL, so the DispatcherServlet
knows which method should be invoked by a specific request. Then the DispatcherServlet
use a HandlerAdapter
to invoke the method.
Why DispatcherServlet does not invoke a method directly?
Because there are many ways to invoke a method, like annotation, xml etc. HandlerAdapter
de-couples the DispatcherServlet
and the invoked actions.
This section of the Spring docs discusses the default adapters and how they relate to annotation configuration.
Briefly, handler adapters decide which controller (and method) to call for a request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With