关于spring mvc的No adapter for handler异常

Posted 滴滴哒滴哒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于spring mvc的No adapter for handler异常相关的知识,希望对你有一定的参考价值。

使用非注解的方式SimpleControllerHandlerAdapter,构造controller,报错

javax.servlet.ServletException: No adapter for handler [cn.com.mvc.controller.FruitsControllerTest@5d99eab6]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
	org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1162)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

 

需要在springmvc的xml配置文件中设置

 <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

并且SampleController需要去实现

org.springframework.web.servlet.mvc.Controller

并且重写handleRequest这个方法去响应请求

 

以上是关于关于spring mvc的No adapter for handler异常的主要内容,如果未能解决你的问题,请参考以下文章

spring mvc No ServletContext set

spring mvc swagger no operations defined in spec,怎么解决

解决Spring MVC no handler抛出异常

Spring MVC PageNotFound.noHandlerFound No mapping found for HTTP request with URI

Thymeleaf with Spring MVC error No mapping found for HTTP request with URI

为啥 Spring MVC 以 404 响应并报告“No mapping found for HTTP request with URI [...] in DispatcherServlet”?