[英]java.lang.NoClassDefFoundError Could not initialize class org.springframework.mock.web.MockServletContext
We are using Spring-test-4.0.6
jar in test scope in our project. 我们在项目的测试范围中使用
Spring-test-4.0.6
jar。 Under same project we also have javaee-6.0
dependency in provided scope. 在同一项目下,我们在提供的范围内还具有
javaee-6.0
依赖项。
I am getting this error in test case 我在测试用例中遇到此错误
Could not initialize class org.springframework.mock.web.MockServletContext at com.sample.TestWebDOMConfiguratorMultiple.setUp(TestWebDOMConfiguratorMultiple.java:77
) Could not initialize class org.springframework.mock.web.MockServletContext at com.sample.TestWebDOMConfiguratorMultiple.setUp(TestWebDOMConfiguratorMultiple.java:77
) Could not initialize class org.springframework.mock.web.MockServletContext at com.sample.TestWebDOMConfiguratorMultiple.setUp(TestWebDOMConfiguratorMultiple.java:77
Surprisingly replacing Javaee-6.
令人惊讶的是替换
Javaee-6.
0 dependency with servlet-api-3.0.1
resolves this issue. servlet-api-3.0.1
0依赖关系解决了此问题。
Note: Spring-4.0.6
pom has compile time optional dependency on servlet-api-3.0.1
. 注意:
Spring-4.0.6
pom对servlet-api-3.0.1
具有编译时可选依赖servlet-api-3.0.1
。
Question is why is it working with servlet-3.0.1
and not with javaee 6.0
as we are trying to replace servlet-api-3.0.1
with javaee-6.0
. 问题是为什么它与
servlet-3.0.1
一起使用而不与javaee 6.0
因为我们正尝试将servlet-api-3.0.1
替换为javaee-6.0
。
Thanks in advance. 提前致谢。
Without knowing the exact artifact that you are referring to as javaee-6.0
and without being able to see the full stack trace, it appears that your javaee-6.0
dependency contains Servlet API 3.0; 在不知道您所指的是
javaee-6.0
的确切工件的情况下,并且无法看到完整的堆栈跟踪信息时,看来您的javaee-6.0
依赖项包含Servlet API 3.0。 whereas, spring-test-4.0.6.RELEASE
explicitly requires Servlet API 3.0.1. 而
spring-test-4.0.6.RELEASE
明确要求Servlet API 3.0.1。
So that is likely the source of your problem. 因此,这可能是您问题的根源。
Regards, 问候,
Sam 山姆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.