Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler

Tags:

I wanted to use both annotation mapping and xml mapping in Spring MVC. My application-context.xml as follows:

<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.

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?

like image 266
Mugu Avatar asked Aug 29 '14 13:08

Mugu


People also ask

Where we can configure DispatcherServlet?

The Spring DispatcherServlet uses special beans to process requests and render the appropriate views. These beans are part of Spring Framework. You can configure them in the WebApplicationContext , just as you configure any other bean.

What is HandlerAdapter?

What Is a Handleradapter? The HandlerAdapter is basically an interface which facilitates the handling of HTTP requests in a very flexible manner in Spring MVC. It's used in conjunction with the HandlerMapping, which maps a method to a specific URL. The DispatcherServlet then uses a HandlerAdapter to invoke this method.

What is a DispatcherServlet in Spring boot?

The DispatcherServlet is the front controller in Spring web applications. It's used to create web applications and REST services in Spring MVC. In a traditional Spring web application, this servlet is defined in the web. xml file.

What are the different parts of the DispatcherServlet?

There are three main parts to this: setting the prefix, which sets the default URL path to find the set views within. the default view type which is set via the suffix. setting a view class on the resolver which allows technologies like JSTL or Tiles to be associated with the rendered views.


1 Answers

This error also occurs when you define a restController but forget to define the requestMapping.

@RestController @RequestMapping("/api/orders") // <---- dont't forget the requestMapping 
like image 171
leo valeriano Avatar answered Sep 21 '22 23:09

leo valeriano