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

6

38

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?

Amadaamadas answered 29/8, 2014 at 13:28 Comment(1)
start by not mixing annotation based mvc and xml-based one. If you want to use <mvc:annotation-driven/> then do so.Amateurism
R
75

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

@RestController
@RequestMapping("/api/orders") // <---- dont't forget the requestMapping
Reluctant answered 8/3, 2021 at 11:17 Comment(0)
I
32

This problem occurred for me when I tried to define RestController path by using in this way:

@RestController("/test")
public class TestController {}

In the above section, the meaning of this declaration is different. Here actually "/test" is defined as bean name rather than path for the controller.

After defining the path in this way it worked for me:

@RestController
@RequestMapping("/test")
public class TestController {}
Iq answered 23/3, 2022 at 11:26 Comment(0)
A
12

I resolved the issue. I forgot to add the @Controller annotation in controller class. There are fore we can use the both methods(annotation mapping & XML mapping) together in an application.

Amadaamadas answered 29/8, 2014 at 17:5 Comment(1)
Switch to Spring Boot for simplicity.Marilla
P
2

Try adding the following as a handler mapper(Worked for me):

<bean id="HandlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
Preachy answered 25/9, 2018 at 19:8 Comment(0)
G
1

Make sure you have implemented Controller in your controller classes and overrided handleRequest method.

Goldina answered 17/5, 2018 at 16:54 Comment(0)
Q
0

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; }
Quillan answered 19/8, 2019 at 8:19 Comment(1)
public class AppController implements Controller{ also worksQuillan

© 2022 - 2024 — McMap. All rights reserved.