java - 您的处理程序是否实现了像 Controller 这样受支持的接口(interface)?

标签 java spring spring-mvc

添加mvc:resource后,我的应用程序抛出如下错误

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

当我使用以下配置时,它工作正常,

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

但是当我添加 Controller 时出现错误。请检查以下配置

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


但如果我删除

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

这个标签,工作正常。我花了很多时间来解决这个问题:(提前致谢

最佳答案

添加这两个标签后,终于成功了..

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

谢谢大家:)

关于java - 您的处理程序是否实现了像 Controller 这样受支持的接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361392/

相关文章:

java - 如果浏览器定向到错误的 URL,如何进行测试 "fail"

java - 通过 Maven/Testng 通过动态自定义 TestNG 文件运行测试

java - 创建名称为 'passwordEncoder' : Requested bean is currently in creation 的 bean 时出错

java - 不支持请求方法 'POST'

java - 对象列表作为 Spring MVC 中的 RequestParam

java - JAXB - 编码单引号字符代码

java - 循环时获取 "Neither BindingResult nor plain target object for bean name ' bean name' 作为请求属性可用

java - Spring-data-neo4j + @Query 抛出 PropertyReferenceException

Spring MVC URIEncoding 无法正确发送请求参数

java - Spring MVC - 2 个不同的 Web 应用程序尝试彼此交互(安全)