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)
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"/>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" />
http://forum.springsource.org/showthread.php?p=182204