Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No adapter for handler exception

I'm developing a web application using spring mvc framework. I want to to both annotation and beanName based url mappings.

I've the following configurations in my context file

<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>

My annotation based controllers are working fine but beanNamed based url mapping are throwing the exception "No adapter for handler".

What am I doing wrong here?

Thank you

like image 976
Harish Avatar asked Oct 09 '10 06:10

Harish


2 Answers

By default the spring mvc defines 3 different request handler adapters, they are

org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

So you need not have to define them in your context file, but if you define at least one handler adapter in your context files, spring will not create the default adapters.

In your configuraion you are using <mvc:annotation-driven />, according to this spring documentation this will cause the context to define both DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter. Since we are creating the AnnotationMethodHandlerAdapter in our context definition spring will not create the other two handlerAdapters. That is why you are getting the said exception.

The beanNameUrlMapping needs the handlerAdapter SimpleControllerHandlerAdapter.

To resolve this exception you can simply create a new bean of type "SimpleControllerHandlerAdapter" in your context.

<bean
    class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter">
</bean>
like image 69
Arun P Johny Avatar answered Oct 20 '22 01:10

Arun P Johny


The same thing happened to me when I was trying to integrate spring MVC 2.5 with spring web flow. For webflow I have given FlowHandlerdAdapter in the configuration file but none for MVC. Thereby as said above we need to define a BEAN of type simplecontrollerhandleradapter in this case which will solve the problem.

like image 38
Ankit Avatar answered Oct 19 '22 23:10

Ankit