Wednesday, February 10, 2010

Spring annotations with spring-mock gotchas

Spring version used: Spring 2.5.6 but spring-mock2.0 (as that's the latest version for mock)

Problem: Junits do not run from dos(when using spring-mock) . Throws  weird exceptions:
java.lang.NoSuchMethodError:springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass(Ljava/lang/Class;Ljava/lang/Class; org.)

The cause: spring-mock 2.0 tries to load spring2.0 jars into classpath screwing up junits run using spring annotations.

Solution:  Tried excluding all the spring-mock dependencies. This should have ideally worked. But I was not able to get it exclude it ...dont know could be a  maven version bug?? Hence had to modify the local pom.xml of spring-mock and removed all spring 2.0 dependencies. Put it into our local maven mirror(archiva).

How did i find this out: By using mvn -X test one can see all the jars loaded in classpath
Details: See a similar problem well explained here




No comments: