Does your handler implement a supported interface like Controller?

早过忘川 提交于 2021-01-28 12:49:37

问题


After adding mvc:resource my application throwing error like

"javax.servlet.ServletException: No adapter for handler [com.test.web.controller.AppController@190cf5c]: Does your handler implement a supported interface like Controller?"

when i use below configuration it's workin fine,

          <?xml version="1.0" encoding="UTF-8"?>
       <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
     http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

 <mvc:resources mapping="/help/**" location="/help/" />
<!-- View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/jsp/" p:suffix=".jsp" />

<bean id="xmlFileViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    <property name="location">
        <value>/WEB-INF/views.xml</value>
    </property>
    <property name="order">
        <value>1</value>
    </property>
</bean> 

But when i add my controller's i'm getting error. pls check the below configuration

 <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans                      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
     http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

 <mvc:resources mapping="/help/**" location="/help/" />
<!-- View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/jsp/" p:suffix=".jsp" />

<bean id="xmlFileViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    <property name="location">
        <value>/WEB-INF/views.xml</value>
    </property>
    <property name="order">
        <value>1</value>
    </property>
</bean>


<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- one of the properties available; the maximum file size in bytes -->
    <!-- maximum file size (1 megabyte) -->
    <property name="maxUploadSize" value="6048576" />
</bean>

<bean id="urlMapping"   class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">


    <property name="mappings">
        <props>
            <!-- Login -->
            <prop key="/login.htm">appController</prop> 
            <prop key="/index.htm">appController</prop>

            </props>
    </property>
</bean>


<bean name="appController" class="com.test.web.controller.AppController" >
    </bean>


but if i remove

<mvc:resources mapping="/help/**" location="/help/" />

this tag, it's working fine. I spend lot time to figure this one :( Thanks in advance


回答1:


After adding these two tags, it is finally worked..

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> 
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="order" value="0"/>
</bean>          

Thanks everyone :)




回答2:


In my case, I needed to add this adapter too.

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



回答3:


If it is a portlet, like liferay portlet then you need to add

...<bean class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> also make sure that your controller has @Controller annotation and your controller method has @RequestMapping("VIEW")



来源:https://stackoverflow.com/questions/24361392/does-your-handler-implement-a-supported-interface-like-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!