After finishing the Maven Pom.xml file today, I integrated several projects with MAVEN, resulting in a wonderful error when starting Tomcat:
Severity: servlet [spring] in web application [/abcweb] threw load () exceptionjava.lang.incompatibleclasschangeerror: class org.springframework.core.type.classreading.classmetadatareadingvisitor has interface Org.springframework.asm.classvisitor as super classat java.lang.classloader.defineclass1 ( Native method) At java.lang.classloader.defineclass (classloader.java:800) at Java.security.SecureClassLoader.defineClass (secureclassloader.java:142) at Org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal (webappclassloaderbase.java:2495) at Org.apache.catalina.loader.WebappClassLoaderBase.findClass (webappclassloaderbase.java:859) at Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1301) at Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1166) at Java.lang.ClassLoader.defineClass1 (native Method)
Restart the Tomcat,project>clean have played all over, also did not find the problem where ... So Google, the results from this page found such a paragraph:
Your Newly packaged library is not backward binary compatible (BC) with an old version. For this reason some of the library clients that is not recompiled may throw the exception.
this is a complete list of changes in Java library API., cause clients built with a old version of the library to thro W Java.lang. Incompatibleclasschangeerror if They run on a new one (i.e. breaking BC):
non-final field become static,
Non-constant Field become non-static,
Class become interface,
Interface become class,
If you add a new field to Class/interface (or add new Super-class/super-interface) then a static field from a Super-interf Ace of a client class C may hide an added field (with the same name) inherited from the super-class of C (very rare case).
In fact, the careful point can be found that the error description is actually very clear:
Java.lang.IncompatibleClassChangeError:class Org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface Org.springframework.asm.ClassVisitor as Super class
It means that there is a class called Classmetadatareadingvisitor, with an interface called Classvisitor as the parent class . But everyone knows thatthe relationship between classes and interfaces in Java can only be implemented, not inherited . So why does this class appear? I'm trying to open this error class in eclipse:
As you can see, the Classmetadatareadingvisitor classes of two versions (3.2.6 and 4.0.0) can be found in my workspace, open these two classes (Maven automatically downloads the source code), and you can see that the class declaration is:
Class Classmetadatareadingvisitor extends Classvisitor implements Classmetadata
So I opened the Classvisitor class mentioned in the error description, and the result is this:
As you can see, Eclipse found 3 such classes in workspace, and the package name class names are exactly the same. As you can see, in the Spring version 3.1.4, this class called Classvisitor is actually an interface that is placed in the Spring-asm module. In 3.2.6 and 4.0.0, this classvisitor becomes an abstract class.
After discovering this difference, I checked the version of my Spring-core module:
<dependency> <groupId>org.springframework</groupId> <artifactid>spring-core</ Artifactid> <version>3.2.6</version></dependency>
But at the same time my pom.xml has a dependency on such a package:
<dependency> <groupId>org.springframework</groupId> <artifactid>spring-asm</ Artifactid> <version>3.1.4.RELEASE</version></dependency>
Just this 3.1.4 interface is in the workspace, so the two packages have this classvisitor, delete the Spring-asm module, the error disappears, solve the problem.
This spring-asm bag also does not know when to import, this tells us:
When using Maven to handle the dependency package, do not randomly add dependencies, the use of the package is imported, no use to the package declaration to be deleted in time.
When consolidating multiple MAVEN projects, be aware of the version of the dependent package, because some classes (which may contain fields) may be declared differently in different versions, and incorrect class or field declarations will cause incompatibleclasschangeerror.
Reference page:
Http://stackoverflow.com/questions/1980452/what-causes-java-lang-incompatibleclasschangeerror
Solve Java.lang.IncompatibleClassChangeError