在Spring MVC框架中,当通过注解@Controller方式实现控制器和其他不同类型的控制器(如继承Controller的方式的控制器)一起使用的时候,通常需要配置Adapter.
1,在和继承SimpleFormController 作为控制器使用的时候(public class LoginController extends SimpleFormController ),需要在-servlet.xml文件中配置
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>否则会有类似下面的异常
javax.servlet.ServletException: No adapter for handler [com.test.spring.mvc.contoller.LoginController@c6e1ec]:
Does your handler implement a supported interface like Controller?
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:982)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:770)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
2,在和通过HttpInvokerServiceExporter提供HTTP服务一起使用的时候,需要在-servlet.xml文件中配置
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/>否则会有类似下面的异常
javax.servlet.ServletException: No adapter for handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter@45378f]:
Does your handler implement a supported interface like Controller?
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:982)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:770)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)