I recently upgraded one the projects I’m working on to Spring 2.5.1 and at the same time decided to start using JUnit 4 for that same project. We use Maven and so a simple change to pom.xml makes it reality. However, I encountered troubles:
-------------------------------------------------------------------------------
Test set: com.acando.zircon.unit.core.test.dctm.AbstractTestCaseJunit4Test
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.031 sec <<< FAILURE!
initializationError0(com.acando.zircon.unit.core.test.dctm.AbstractTestCaseJunit4Test) Time elapsed: 0.016 sec <<< ERROR!
java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
at org.springframework.test.context.TestContext.retrieveContextLocations(TestContext.java:159)
at org.springframework.test.context.TestContext.
at org.springframework.test.context.TestContextManager.
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:107)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.apache.maven.surefire.junit4.JUnit4TestSet.
at org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet(JUnit4DirectoryTestSuite.java:56)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:96)
at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:209)
at org.apache.maven.surefire.Surefire.run(Surefire.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
Another error I got when trying to fix this was:
[INFO] ————————————————————————
[ERROR] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Compilation failure
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[13,39] package org.springframework.test.context does not exist
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[14,46] package org.springframework.test.context.junit4 does not exist
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[15,46] package org.springframework.test.context.junit4 does not exist
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[33,53] cannot find symbol
symbol: class AbstractJUnit4SpringContextTests
public abstract class AbstractTestCaseJunit4 extends AbstractJUnit4SpringContextTests {
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[32,1] cannot find symbol
symbol: class ContextConfiguration
@ContextConfiguration(locations = { “classpath:/zircon-core-dctm-defaultConfig.xml”, “classpath:/spring-testConfig.xml” })
C:\Work\WS\zircon-core-dctm\src\main\java\com\acando\zircon\core\test\dctm\AbstractTestCaseJunit4.java:[31,9] cannot find symbol
symbol: class SpringJUnit4ClassRunner
@RunWith(SpringJUnit4ClassRunner.class)
These errors seem to indicate an older version of Spring in my classpath, and to track it down I removed all the Spring jars from my ~.m2/repository folder and ran mvn clean test again.
Aha! Some dependancy still downloads Spring 2.0.7 which in turns comes before my dependancy on Spring 2.5.1. Turns out it was the spring-oxm-tiger version 1.0.3 dependancy from Spring Web Services’ (spring-ws) project that bit me. I could now either exclude that transitive dependancy to Spring or look for a newer version with support for Spring 2.5.
Looked at the Spring WS download page and saw 1.5.0-m2 as the latest version but this version is not available at the default Maven repository, instead only at the Spring milestone repository that you connect to by adding the following to your pom.xml:
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Repository</name>
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
</repository>
</repositories>
The dependency to spring-oxm looks like this:
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-oxm-tiger</artifactId>
<version>1.5.0-m2</version>
</dependency>
A simple mvn clean test will now make your project smile again I hope!
Recent Comments