Results 1 to 7 of 7

Thread: Error using AnnotationMethodHandlerAdapter and UrlFilenameViewController

  1. #1
    Join Date
    Mar 2007
    Posts
    13

    Default Error using AnnotationMethodHandlerAdapter and UrlFilenameViewController

    I am currently trying to use a combination of the MVC annotations like @Controller with some of the pre-2.5 Spring features like UrlFilenameViewController for static views. Unfortunately when I combine an AnnotationMethodHandlerAdapter and UrlFilenameViewController within the same web application I get this error:
    Code:
    javax.servlet.ServletException: No adapter for handler [org.springframework.web.servlet.mvc.UrlFilenameViewController@43fb68]: Does your handler implement a supported interface like Controller?
    	org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1090)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:873)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:453)
    Any ideas? Thanks !!!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    For the older controller to work you need a explicitly registered HandlerMapping like SimpleUrlHandlerMapping. Remember to also register a DefaultAnnotationHandlerMapping because the explicit registering will override the defaults.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Mar 2007
    Posts
    13

    Default

    I did. Here is my configuration:
    Code:
        <bean id="web.siteMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="web.localeChangeInterceptor"/>
                </list>
            </property>
            <property name="mappings">
                <props>           
                    <prop key="/login.htm">web.staticViewController</prop>
                    <prop key="/notAuthorized.htm">web.staticViewController</prop>
            </property>
        </bean>
        
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
    
     <bean id="web.staticViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

  4. #4
    Join Date
    Apr 2007
    Location
    Wellington, New Zealand
    Posts
    125

    Default

    Hi fjavier,

    The dispatcher servlet gives you a couple of things for free out of the box, including two types of handler mappers, and four handler adapters, including the AnnotationMethodHandlerAdapter and SimpleControllerHandlerAdapter.

    When you want to mix 2.0 and 2.5 styled controllers together you do not need to define a AnnotationMethodHandlerAdapter, but you do need to define a DefaultAnnotationHandlerMapping class because once you define another mapper you override all mappers. eg.

    Code:
    <context:component-scan base-package="com.stuff.web" />
          
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
        	p:order="0" />
    
    <bean id="web.siteMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="web.localeChangeInterceptor"/>
            </list>
        </property>
        <property name="mappings">
            <props>           
                <prop key="/login.htm">web.staticViewController</prop>
                <prop key="/notAuthorized.htm">web.staticViewController</prop>
        </property>
    </bean>
        
    <bean id="web.staticViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
    Hope this helps

    Josh

  5. #5
    Join Date
    Mar 2005
    Posts
    5

    Default alternative for fans of BeanNameUrlHandlerMapping

    Same as above, but uses the BeanNameUrlHandlerMapping class and an Ant wildcard path so you don't need to explicitly map all of your static pages:

    Code:
      <!-- VIEWS -->
      <bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/>
    
      <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
    
      <!-- HANDLERS -->
      <context:component-scan base-package="com.example.web"/>
    
      <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="0" />
      </bean>
      
      <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
        <property name="order" value="1" />
      </bean>
    
      <bean name="/**/*.do" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

  6. #6
    Join Date
    Nov 2008
    Posts
    9

    Default

    The exception is due to the fact that registering any instance of a HandlerAdapter leaves without effect the default one. The default one is what makes plain old Spring MVC controllers work normally.
    Fortunately, simply adding it explicitly alongside the other handleradapters made my app work and the exception dissapeared. i.e., just add this to your conf:

    Code:
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    Hope this helps.

  7. #7
    Join Date
    Dec 2012
    Posts
    3

    Default I am facing this issue in spring3.0.1 version above solutions not working

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schem...ontext-3.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <context:component-scan
    base-package="mypack" />



    <bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping"/>

    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter"/>
    <bean class="org.springframework.web.servlet.mvc.SimpleC ontrollerHandlerAdapter"/>




    <bean id="SListController" autowire="byName"
    class="mypack.SListController">
    <property name="Helper" ref="SListHelper" />
    <property name="bDelegate" ref="SListBDelegate" />
    <property name="ResHelper" ref="SListResHelper" />

    </bean>


    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <map>
    <entry key="/authreg_abc.do"><ref bean="TestGenericController"/></entry>
    <entry key="/authreg_doc.do"><ref bean="TestBridgeController"/></entry>
    <entry key="/authreg_pay.do"><ref bean="TestUtilController"/></entry>
    <entry key="/authreg_sest.do"><ref bean="SListController"/></entry>
    </map>
    </property>
    </bean>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •