升级到spring 4.0.3后,Junit 4测试没有运行

时间:2014-05-27 14:23:25

标签: java eclipse spring junit gradle

我有很多测试在我的日食中作为JUnit测试运行。

我刚刚从Spring 3.X升级到弹簧4.0.3,每当我尝试执行junit测试时,我都会遇到一个不确定的异常:

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:126)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:137)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:137)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:96)
at org.springframework.test.context.ContextLoaderUtils.resolveActiveProfiles(ContextLoaderUtils.java:499)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:722)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:656)
at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:119)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
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)

我的gradle依赖项文件:

repositories { mavenCentral() }

  dependencies {
compile group: 'javax.servlet', name:'servlet-api', version:'2.5'
compile group: 'org.springframework', name:'spring-beans', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-messaging', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-websocket', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-context', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-core', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-expression', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-web', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name: 'spring-jms', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version:'4.0.3.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version:'1.3.2.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version:'1.4.2.RELEASE'
compile group: 'org.springframework.security', name:'spring-security-core', version:'3.2.0.RELEASE'
compile group: 'org.springframework.security', name:'spring-security-web', version:'3.2.3.RELEASE'
compile group: 'org.springframework.security', name:'spring-security-config',  version:'3.2.0.RELEASE'
compile group: 'org.springframework', name:'spring-context-support', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-instrument', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-aop', version:'4.0.3.RELEASE'
compile group: 'org.springframework', name:'spring-support', version:'2.0.8'

...
testCompile group: 'junit', name: 'junit', version: '4.+'

这是我的基础测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/application-context.xml" })
public abstract class BaseTest { ... }

任何想法发生了什么?

0 个答案:

没有答案