本文介绍了Spring + java.lang.NoSuchFieldError:NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个使用注释的单元测试用例 @RunWith(SpringJUnit4ClassRunner.class).

I have one unit test case which uses the annotation @RunWith(SpringJUnit4ClassRunner.class).

一切都可以在spring 2.5.6和@RunWith(SpringJUnit4ClassRunner.class)批注中正常运行.但是,当我将spring版本转换为3.2.2-Release时,如果使用@RunWith(SpringJUnit4ClassRunner.class),则会引发以下异常

Everything works fine with spring 2.5.6 and with @RunWith(SpringJUnit4ClassRunner.class) annotation.But when i shift spring version to 3.2.2-Release and if @RunWith(SpringJUnit4ClassRunner.class) is used it throws the following exception

java.lang.NoSuchFieldError: NULL
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:48)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:104)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

但是对于spring 3.2.2-Release,当不使用@RunWith(SpringJUnit4ClassRunner.class)时,它就可以正常工作.

But with spring 3.2.2-Release and when @RunWith(SpringJUnit4ClassRunner.class) is NOT used it just works fine.

我在pom中具有以下依赖性

I have the following dependency in my pom

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>

不知道出了什么问题!

推荐答案

这很可能是由于从依赖项中导入了有冲突的JUnit版本.我有同样的问题,我发现它是由org.jmock:jmock-junit4的传递依赖引起的.当我将其替换为org.jmock:jmock时,此问题已修复.

This is most likely due to importing conflicting versions of JUnit from your dependencies. I had the same problem and I found out it was caused by a transitive dependency with org.jmock:jmock-junit4. It was fixed when I replaced it with org.jmock:jmock.

这篇关于Spring + java.lang.NoSuchFieldError:NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:50