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

     
  • 相关阅读:
    双栈排序
    Koishi Loves Segments
    [USACO14FEB] Cow Decathlon 牛的十项全能
    [HNOI2016]网络
    koishi的数学题
    邦邦的大合唱站队
    #613(div2)
    Educational Codeforces Round 77
    #Hello 2020
    #601 (Div. 2)
  • 原文地址:https://www.cnblogs.com/Courage129/p/12679092.html
Copyright © 2011-2022 走看看