使用mock测试Controller时报错如下

java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
at org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder.initWebAppContext(StandaloneMockMvcBuilder.java:311)
at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:127)
at com.springinaction.spittr.controller.HomeControllerTest.testHome(HomeControllerTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException: javax.servlet.SessionCookieConfig
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 29 more

在 debug 模式下,可以知道 standaloneSetup(clrr) 得到的是 StandaloneMockMvcBuilder 对象和 exception 中报异常的类名一致。

在 Cannot create MockHttpSession with servlet 2.x, spring得到下面有用提示:Spring 4.0 需要得到 servlet 3.0 或以上版本的支持。

The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher, as can be seen inGitHub commit deba32cad9.

追踪上面的 github 链接,可以发现 SessionCookieConfig 是在升级 servlet API 到 3.0 变动中新增的。

在查询SessionCookieConfig 文档,可以知道 SessionCookieConfig 是在 servlet 3.0 才引入的。

反观自己项目 pom.xml ,用的是 servlet 2.5 ,可以判断得到,是自己项目引用的 servlet 版本过低导致的,需要升级到 3.0 或以上。

mock测试SpringMVC controller报错的更多相关文章

  1. 关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx.xml]

    关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx ...

  2. 导入MySQL测试数据库employee报错

    导入MySQL测试数据库employee 报错 下载地址:https://launchpad.net/test-db/ 上传解压: [root@001 ~]# tar xf employees_db- ...

  3. Spring-test使用JUnit时,测试类autowired报错,create bean error

    Spring-test使用JUnit时,测试类里面使用autowired会报错, 报create bean error...... 但是controller里面@autowired可以正常运行的. 在 ...

  4. IDEA新建SpringMVC项目报错解决办法

    网页运行的错误: HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundE ...

  5. python+Django+test 测试数据库生成报错

    前提: 使用Django自带的test进行单元测试. 问题描述: 运行:python manage.py test,报错,出现数据库乱码的现象,报错如下: Creating test database ...

  6. 项目中访问controller报错:HTTP Status 500 - Servlet.init() for servlet spring threw exception

    直接访问controller路径http://localhost:8080/index报错: HTTP Status 500 - Servlet.init() for servlet spring t ...

  7. SpringMVC版本报错解决办法

    报错代码: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  8. struts配置测试中遇到报错信息,记录下

    tomcat7 jdk7myeclipse2014 部署完成后,访问页面报错struts.xml文件内容: <?xml version="1.0" encoding=&quo ...

  9. spring-mvc.xml报错cvc-complex-type.2.4.c

    添加 <!-- 定义请求处理映射HandlerMapping --> <bean id = "handlerMapping" class = "org. ...

随机推荐

  1. 用html+css做机器猫 源代码

    先来看一下做出来的效果图,然后再来看源代码 是不是还是很像的 下面来看源代码 <!DOCTYPE html> <html lang="en"> <he ...

  2. 部署jenkins问题

    总结:配置的url,jenkins部署的ip必须有开放,否则发布会超时失败

  3. kali虚拟机安装后操作[配置ssh,安装vmtools,更新源]

    更新源 # 打开控制台, 输入以下命令打开编辑器修改配置文件 $ leafpad /etc/apt/sources.list #kali官方源 deb http://http.kali.org/kal ...

  4. 开源ITIL管理软件iTop 2.5-2.6安装

    环境说明 : 操作系统centos 7.itop版本 iTop-2.5.0-3935.数据库:mariadb iTop 2.5只支持PHP5.6以上版本,本例安装的是php72w版本 1.下载链接: ...

  5. CocoStuff—基于Deeplab训练数据的标定工具【四、用该工具标定个人数据】

    一.说明 本文为系列博客第四篇,主要讲述笔者在正式使用该工具使用自定义标签标注自己的图片的过程. 二.数据整理 相信大家已经在 *占坑

  6. 08-matplotlib-颜色与样式

    import numpy as np import matplotlib.pyplot as plt ''' 颜色: - 八种内置默认颜色, 缩写 b :blue g :green r :red c ...

  7. Docker入门与实践之 Dockerfile 语法详解

    一.Dockerfile 概述 Dockerfile是docker程序的解释脚本文件,Dockerfile 是一条一条的指令,Docker程序将dockerfile中的一条条指令编译成Linux可执行 ...

  8. Python函数初识

    一.函数是什么 ​ 计算机语言中的函数是类比于数学中的函数演变来的,但是又有所不同.前面的知识中我们学会了运用基础语法(列表.字典)和流程控制语句貌似也能处理一些复杂的问题,但是相对于相似的大量重复性 ...

  9. 编译Android VNC Server

    1,在如下地址checkout源代码,我checkout的版本为0.9.7http://code.google.com/p/android-vnc-server/source/checkout 2,在 ...

  10. 2-Tenth Scrum Meeting20151210

    任务分配 闫昊: 今日完成:请假.(编译) 明日任务:参加会议讨论,安排任务分工. 唐彬: 今日完成:请假.(编译) 明日任务:参加会议讨论,安排任务分工. 史烨轩: 今日完成:请假.(编译) 明日任 ...