Spring JUnit Test Error Spring JUnit Test Error spring spring

Spring JUnit Test Error


I had this exact same issue when upgrading from Spring 3.0.6 and to 3.1.0 release. Here is the solution:

Some of your dependencies are listed as being the 3.1.0 version, but they resolve their transitive dependencies to the older versions which don't have the method listed in the error message.

If you use Eclipse, open the pom.xml and look at the dependency hierarchy tab. Some libraries you declared will be listed as version 3.1.0 but have a resolved dependency of 3.0.6. For me, I had spring-security-config and spring-security-taglibs listed as version 3.1 in my pom, but they resolved dependencies such as spring-core and spring-expression as 3.0.6.

To resolve this, explicitly list each of the highest transitive dependencies explicitly in your pom. For example, I was originally counting on spring-security-config to bring in spring-core as a transitive dependency, so I did not list the spring-core artifact in my pom. But to fix this issue I changed my pom to explicitly include spring-core (version 3.1.0). I added direct dependencies for every resolved dependency in my pom that was being resolved to an older version, and then it worked!

Hope this helps...


If solutions above are not working, it might be eclipse's fault: in eclipse, on the project -> properties -> java build path -> Librairies -> if there is "Junit 4", remove it.

I had this stacktrace:

java.lang.NoSuchMethodError: org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runLeaf(Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;Lorg/junit/runner/notification/RunNotifier;)V    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)

And of course updating the pom wasn't the solution...


In my case,I had dependency one junit-dep and one junit, when I remove the junit-dep, everything is ok.