Error using AnnotationMethodHandlerAdapter and UrlFilenameViewController

53 篇文章 0 订阅

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值