zoukankan      html  css  js  c++  java
  • javax.servlet.ServletException: No adapter for handler

    问题描述:

     我的web.xml如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    <!--前端控制器DispactherServlet-->
        <servlet>
            <servlet-name>springmvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:springmvc.xml</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
    </web-app>

    springmvc.xml如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!--扫包-->
        <context:component-scan base-package="com.courage"></context:component-scan>
    
        <!--映射器-->
        <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
        <!--适配器-->
        <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
        <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/>
        <!--解析器-->
        <bean id="internalResourceViewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="WEB-INF/page/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    
        <bean id="/test01" class="com.courage.controller.FirstController"></bean>
    
    </beans>

    Controller如下:

    package com.courage.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class FirstController {
    
        @RequestMapping("/test01")
        public String test01(){
            System.out.println("test01");
            return "success";
        }
    }

    解决办法:

    springmvc.xml中删掉:

     <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
     <bean id="/test01" class="com.courage.controller.FirstController"></bean>

    springmvc.xml中添加:

    <mvc:annotation-driven />

    原因:

    https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc

     
  • 相关阅读:
    python报错:ERROR: No matching distribution found for dns.resolver
    CVE-2013-4710 WebView addJavascriptInterface远程执行代码
    AndroiBugs Android漏洞扫描器
    如何预测股票分析--线性回归
    如何预测股票分析--移动平均
    Mac升级后如何查看自己的网络端口
    盘它!!一步到位,Tensorflow 2的实战 !!LSTM下的股票预测(附详尽代码及数据集)
    找了好久的塔塔饮料数据集!!!!
    dataset中shuffle()、repeat()、batch()用法
    关于Matplotlib中No module named 'matplotlib.finance'的解决办法
  • 原文地址:https://www.cnblogs.com/Courage129/p/12679092.html
Copyright © 2011-2022 走看看