[JavaEE] Spring单元测试中缺少 ServletContext 错误
来源:互联网 发布:java经典代码大全 编辑:程序博客网 时间:2024/06/05 17:27
在Spring单元测试中出现了如下错误,
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
出现上面错误的原因是:
在配置Junit的运行环境的过程中,需要使用@ContextConfiguration(xxx.class)
指定@Configuration
类。由于指定的类中包含了含有@EnableWebMvc
注解的类,所以出现上述错误。
解决办法:
- 方法1:
@ContextConfiguration
不要包含带有@EnableWebMvc
注解的类 - 放法2:在测试类中加入
@WebApplicationContext
注解来配置Servlet环境。
参考:
[1]https://stackoverflow.com/questions/21516683/java-lang-illegalargumentexception-a-servletcontext-is-required-to-configure-de
阅读全文
0 0
- [JavaEE] Spring单元测试中缺少 ServletContext 错误
- Spring中获取servletContext
- spring aop错误 缺少jar
- Spring缺少jar包错误
- Tomcat中通过JavaEE实现的WebSocket程序获取ServletContext
- Spring单元测试类ApplicationTests错误
- 缺少spring.jar包的低级错误
- 在spring的bean中获取ServletContext
- 在spring的bean中获取ServletContext
- Spring:在bean中获取ServletContext
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring 中获取servletContext及WebApplicationContext
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring 中获取servletContext及WebApplicationContext
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- linux下创建函数库
- Python实现简易记事本
- JSP详细DAO设计模式及应用(!)
- Gulp入门指南
- Java获取当前日期加上指定天数后的日期
- [JavaEE] Spring单元测试中缺少 ServletContext 错误
- 使用shader效果
- Java8 新特性
- Linux Kernel 学习笔记13:混杂设备模型
- didn't find class on path dexpathlist错误解决办法
- 10391
- 认识grep -e, tr, xargs
- dubbo 4 服务消费者到提供者过程
- 动态规划——最长上升子序列