最近刚在学习 Spring MVC,今天碰到了一个问题:
我使用基于注解的 Controller,然后添加了一个 ParameterizableViewController, id 是 successController。再运行时以前的基于注解的 Controller 能很好工作,但是到 successController 时,Spring 就会抛出异常: javax.servlet.ServletException: No adapter for handler 。
先说解决方案:
在 Spring MVC 上下文中添加两个 bean:
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
具体原因如下:
Spring MVC 默认会声明3个请求 handler adapter:
org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter