spring mvc No ServletContext set
Posted 请叫我大师兄_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring mvc No ServletContext set相关的知识,希望对你有一定的参考价值。
问题:
在执行spring mvc的web的test模块的单元测试方法时候,报错。
报错:Error creating bean with name 'resourceHandlerMapping' defined in com.mvc.test.WebConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
解决方案:
在spring test类上加:@WebAppConfiguration("src/main/resources")
以上是关于spring mvc No ServletContext set的主要内容,如果未能解决你的问题,请参考以下文章
关于spring mvc的No adapter for handler异常
spring mvc swagger no operations defined in spec,怎么解决
Spring MVC PageNotFound.noHandlerFound No mapping found for HTTP request with URI
Thymeleaf with Spring MVC error No mapping found for HTTP request with URI
为啥 Spring MVC 以 404 响应并报告“No mapping found for HTTP request with URI [...] in DispatcherServlet”?