Announcement Announcement Module
Collapse
No announcement yet.
Error using AnnotationMethodHandlerAdapter and UrlFilenameViewController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 [[email protected]b68]: 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
    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.

    Comment


    • #3
      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"/>

      Comment


      • #4
        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

        Comment


        • #5
          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"/>

          Comment


          • #6
            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.

            Comment


            • #7
              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>

              Comment

              Working...
              X