验证controller报错

验证controller报错

类型 异常报告

消息 Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;

描述 服务器遇到一个意外的情况,阻止它完成请求。

例外情况

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1076)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因。

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
org.springframework.web.util.UrlPathHelper.skipServletPathDetermination(UrlPathHelper.java:265)
org.springframework.web.util.UrlPathHelper.getLookupPathForRequest(UrlPathHelper.java:250)
org.springframework.web.util.UrlPathHelper.resolveAndCacheLookupPath(UrlPathHelper.java:199)
org.springframework.web.servlet.handler.AbstractHandlerMapping.initLookupPath(AbstractHandlerMapping.java:567)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:361)
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:123)
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:66)
org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:491)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1255)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

):注意 主要问题的全部 stack 信息可以在 server logs 里查看

感觉是不是我配置有什么问题,能够正常启动到tomcat的欢迎页面

http://img1.sycdn.imooc.com//climg/60bfec280990e3d207080200.jpg

http://img1.sycdn.imooc.com//climg/60bfec28093a094604590539.jpg

http://img1.sycdn.imooc.com//climg/60bfec290943ada112410494.jpg

http://img1.sycdn.imooc.com//climg/60bfec29094f1aac04930460.jpg

http://img1.sycdn.imooc.com//climg/60bfec29097fffab12700636.jpg

package com.imooc.o2o.service;

import java.util.List;

import com.imooc.o2o.entity.Area;

public interface AreaService {
  List<Area> getAreaList();
}
package com.imooc.o2o.service.impl;

import com.imooc.o2o.dao.AreaDao;
import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AreaServiceImpl implements AreaService {
   @Autowired
   private AreaDao areaDao;

@Override
   public List<Area> getAreaList() {
       return areaDao.queryArea();
}
}
package com.imooc.o2o.service;


import com.imooc.o2o.BaseTest;
import com.imooc.o2o.entity.Area;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class AreaServiceTest extends BaseTest {

   @Autowired
   private AreaService areaService;

@Test
   public void testGetAreaList(){
       List<Area> areaList = areaService.getAreaList();
assertEquals("西苑", areaList.get(0).getAreaName());

}

}
package com.imooc.o2o.web.superadmin;


import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/superadmin")
public class AreaController {
   @Autowired
   private AreaService areaService;

@RequestMapping(value = "/listarea", method = RequestMethod.GET)
   @ResponseBody
   private Map<String, Object> listArea() {
       Map<String, Object> modelMap = new HashMap<String, Object>();
List<Area> list = new ArrayList<Area>();
try {
           list = areaService.getAreaList();
modelMap.put("rows", list);
modelMap.put("total", list.size());
} catch (Exception e) {
           e.printStackTrace();
modelMap.put("success", false);
modelMap.put("errM", e.toString());
}
       return modelMap;
}


}
<?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"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
  <!-- 配置SpringMVC -->
  <!-- 1.开启SpringMVC注解模式 -->
  <mvc:annotation-driven />

  <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 -->
  <mvc:resources mapping="/resources/**" location="/resources/" />
  <mvc:default-servlet-handler />

  <!-- 3.定义视图解析器 -->
  <bean id="viewResolver"
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/WEB-INF/html/"></property>
     <property name="suffix" value=".html"></property>
  </bean>

  <!-- 4.扫描web相关的bean -->
  <context:component-scan base-package="com.imooc.o2o.web" />

</beans>
<?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"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx.xsd">
   <!-- 扫描service包下所有使用注解的类型 -->
   <context:component-scan base-package="com.imooc.o2o.service" />

   <!-- 配置事务管理器 -->
   <bean id="transactionManager"
       class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <!-- 注入数据库连接池 -->
       <property name="dataSource" ref="dataSource"/>
   </bean>

   <!-- 配置基于注解的声明式事务 -->
   <tx:annotation-driven transaction-manager="transactionManager" />
</beans>
<?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
   http://www.springframework.org/schema/context/spring-context.xsd">
  <!-- 配置整合mybatis过程 -->
  <!-- 1.配置数据库相关参数properties的属性:${url} -->
  <context:property-placeholder location="classpath:jdbc.properties"/>
  <!-- 2.数据库连接池 -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
     <!--配置连接池属性-->
     <property name="driverClass" value="${jdbc.driver}"/>
       <property name="jdbcUrl" value="${jdbc.url}"/>
       <property name="user" value="${jdbc.username}"/>
       <property name="password" value="${jdbc.password}"/>

     <!-- c3p0连接池的私有属性 -->
     <property name="maxPoolSize" value="40" />
     <property name="minPoolSize" value="10" />
     <!-- 关闭连接后不自动commit -->
     <property name="autoCommitOnClose" value="false" />
     <!-- 获取连接超时时间 -->
     <property name="checkoutTimeout" value="10000" />
     <!-- 当获取连接失败重试次数 -->
     <property name="acquireRetryAttempts" value="2" />
  </bean>

  <!-- 3.配置SqlSessionFactory对象 -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
     <!-- 注入数据库连接池 -->
     <property name="dataSource" ref="dataSource" />
     <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
     <property name="configLocation" value="classpath:mybatis-config.xml" />
     <!-- 扫描entity包 使用别名 -->
     <property name="typeAliasesPackage" value="com.imooc.o2o.entity" />
     <!-- 扫描sql配置文件:mapper需要的xml文件 -->
     <property name="mapperLocations" value="classpath:mapper/*.xml" />
  </bean>

  <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
     <!-- 注入sqlSessionFactory -->
     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
     <!-- 给出需要扫描Dao接口包 -->
     <property name="basePackage" value="com.imooc.o2o.dao" />
  </bean>
</beans>
<?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_3_1.xsd"
        version="3.1">
 
<display-name>Archetype Created Web Application</display-name>

   <welcome-file-list>
       <welcome-file>aaa.jsp</welcome-file>
       <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>

   <servlet>
       <servlet-name>spring-dispatcher</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:spring/spring-*.xml</param-value>
       </init-param>
   </servlet>
   <servlet-mapping>
       <servlet-name>spring-dispatcher</servlet-name>
       <!-- 默认匹配所有的请求 -->
       <url-pattern>/</url-pattern>
   </servlet-mapping>


</web-app>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小班 2021-06-09 14:31:28

同学你好,根据报错信息,处理程序调度失败,一般情况下出现这个问题是因为tomcat版本不匹配,同学可以尝试更换tomcat版本再来试试。

祝学习愉快!

  • 提问者 视线模糊 #1

    要用那个版本的Tomcat喃,我现在是8.5,要用9还是7?

    2021-06-09 22:40:01
  • 提问者 视线模糊 #2

    好像和spring的版本有关,我用的5.3.0不行,然后用回老师的spring版本好像可以,但是现在不知道怎么搞的又搞来项目都启动不了,spring5.3.0的话应该用哪个版本的Tomcat喃,之前的OA项目我也是用的spring5.3.0和Tomcat8.5,怎么到了这个项目就不可以了?

    2021-06-09 23:54:40
  • 提问者 视线模糊 #3

    好像和spring的版本有关,我用的5.3.0不行,然后用回老师的spring版本好像可以,但是现在不知道怎么搞的又搞来项目都启动不了,spring5.3.0的话应该用哪个版本的Tomcat喃,之前的OA项目我也是用的spring5.3.0和Tomcat8.5,怎么到了这个项目就不可以了?

    2021-06-09 23:54:55
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师