spring DispatcherServlet 配置需要包含一个支持这个处理程序的 HandlerAdapter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25569303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
提问by Mugu
I wanted to use both annotation mapping and xml mapping in Spring MVC. My application-context.xmlas follows:
我想在 Spring MVC 中同时使用注解映射和 xml 映射。我application-context.xml的如下:
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="personal/account/history">accountHistoryController</prop>
</props>
</property>
</bean>
<bean id="accountHistoryController" class="com.fg.banking.ib.controller.AccountHistoryController" />
<bean
class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
<context:annotation-config />
<mvc:annotation-driven />
<context:component-scan base-package="com.fg.banking.ib.controller, com.fg.banking.ib.helper, com.fg.banking.corporate.controller" />
I am getting the following error when I try to access the url. I have configured the SimpleControllerHandlerAdapter as above.
当我尝试访问 url 时出现以下错误。我已经配置了 SimpleControllerHandlerAdapter 如上所述。
javax.servlet.ServletException: No adapter for handler
[com.fg.banking.ib.controller.AccountHistoryController@218531e6]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1128)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:903)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
What to do?
该怎么办?
回答by Mugu
I resolved the issue. I forgot to add the @Controllerannotation in controller class. There are fore we can use the both methods(annotation mapping & XML mapping) together in an application.
我解决了这个问题。我忘了@Controller在控制器类中添加注释。我们可以在应用程序中同时使用这两种方法(注释映射和 XML 映射)。
回答by Majid
Make sure you have implemented Controllerin your controller classes and overrided handleRequestmethod.
确保您已Controller在控制器类中实现并覆盖handleRequest方法。
回答by Subhranil Sengupta
Try adding the following as a handler mapper(Worked for me):
尝试将以下内容添加为处理程序映射器(对我来说有效):
<bean id="HandlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
回答by Hyder Ali
Here our controller class should extends
这里我们的控制器类应该扩展
import org.springframework.web.servlet.mvc.AbstractController;
public class AppController extends AbstractController{ }
Here we need to implement the abstract method as :
这里我们需要将抽象方法实现为:
protected modelandview handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { return null; }

