Spring mvc HandlerMapping VS HandlerAdapter AND mvc:annotation-driven

HandlerMapping and HandlerAdapter

HandlerMapping and HandlerAdapter are good for rest service testing.

The strategy interface HandlerAdapter takes the role of invoking handler methods selected by some HandlerMapping.

If a HandlerMapping selects a controller, but not a specific method, then the HandlerAdapter also selects the handler method.

DispatcherServlet invokes controllers through HandlerAdapter strategy objects.

This allows for different types of controllers use different method invokation strategies. and URL mapping strategies are possible.

Installing new types of handler invokation strategies requires an appropriate HandlerAdapter bean to be registered.

When multiple HandlerAdapter are installed, the DispatcherServlet will invoke all to check the first that supports the handler object provided by the HandlerMappingstrategy. The first HandlerAdapter that supports the handler object (controller or method) is used to invoke the handler.

Spring MVC supports several types of controllers, including: annotation defined controllers (with @Controller), the WebFlow FlowExecutor etc.


AnnotationMethodHandlerAdapter adapts HTTP requests to handler methods annotated with @RequestMapping. It introspects required input arguments for handlers, and interprets output values. This the HandlerAdapter configured by default.

The AnnotationMethodHandlerAdapter can be used with controller with multiple handler methods in a variety of powerful ways.


<mvc:annotation-driven/> in spring

<mvc:annotation-driven /> declares explicit support for annotation-driven MVC controllers

The tag will configure two beans DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter so that you do not need to declare them in context config file.

find more information from the spring documents:



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s