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?
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 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.
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.
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.
This error also occurs when you define a restController but forget to define the requestMapping.
@RestController @RequestMapping("/api/orders") // <---- dont't forget the requestMapping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With