Junit使用的问题总结

/ Java / 没有评论 / 1470浏览

#1. Service测试类报以下错误:

Caused by: java.lang.IllegalStateException: WebApplicationObjectSupport instance [ResourceHttpRequestHandler [locations=[class path resource [static/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@7b60f290]]] does not run in a WebApplicationContext but in: org.springframework.context.support.GenericApplicationContext@51e96073: startup date [Mon Apr 24 10:26:24 CST 2017]; root of context hierarchy

原因:测试类缺少@WebAppConfiguration注解 解决方案:在测试类添加@WebAppConfiguration注解