views:

37

answers:

1

Hi All,

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 mixed 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"&gt;

    <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 really conflicting.
This is a fairly large Spring MVC apps and I dont 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.

Can somebody help me out on this please?

+2  A: 

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.

skaffman
Hi Skaffman,I tried what you have suggested but I am getting a 404 when I removed these declaration.I already commented out the controller in my mappings thinking that it will autodetect my @controller. <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <!-- <prop key="/home.htm">homeController</prop> -->
Mark Estrada
I forgot to mention that I still have SimpleUrlHandlerMapping configured in my configuration file
Mark Estrada