Mark Estrada
Mark Estrada

Reputation: 9191

Spring MVC annotation error "No adapter for handler - Does your handler implement a supported interface like Controller?"

I have an existing Spring MVC apps written in 2.5.

I wanted to use the new annotation controller. I somewhat see that it is really flexible and would answer my other needs.

My problem is, it seems I cannot mix them both.

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <context:component-scan
            base-package="com.test.web" />

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    <!-- Controller Mappings Here -->
    <bean id="homeController" class="com.test.web.HomeController">
        <property name="cacheSeconds" value="120" />
    </bean> 

    //other plain old spring mvc controller

When I ran my app and hit the home page, I get below error:

javax.servlet.ServletException: No adapter for handler [com.test.web.HomeController@cca07b]: Does your handler implement a supported interface like Controller?

I am not sure but I think something is conflicting. This is a fairly large Spring MVC apps and I don't want to change those modules that were working already using the old Spring Base Controller.

My goal is to only use the annotation controller on my new enhancement.

Upvotes: 0

Views: 1330

Answers (1)

skaffman
skaffman

Reputation: 403461

You don't need to declare DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter. The context has these registered by default, along with adapters for old-style controllers.

When you declare them explicitly like this, the default ones are removed, and the context will only support the ones you declare.

Upvotes: 3

Related Questions