복붙노트

[SPRING] java.lang.IncompatibleClassChangeError : Mongo 클래스 구현

SPRING

java.lang.IncompatibleClassChangeError : Mongo 클래스 구현

왜이 오류가 발생하는지 파악할 수 없습니다. 중복 된 libs 등을 정리하려고했습니다.

내가 할 때 오류가 발생 :

  mongo = new Mongo(host, port);

재미있는 점은 IDE (IntelliJ)에서 만든 단위 테스트를 실행할 수 있다는 것입니다.하지만 Tomcat을 통해 실행하려고하면 다음과 같이됩니다.

  Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.
    sfatandrei.db.MongoManager]: Constructor threw exception; nested exception is java.lang.IncompatibleCla
    ssChangeError: Implementing class
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInst
    antiationStrategy.java:110)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(Constructo
    rResolver.java:280)
        ... 82 more
    Caused by: java.lang.IncompatibleClassChangeError: Implementing class
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
        at com.mongodb.MongoOptions.reset(MongoOptions.java:47)
        at com.mongodb.MongoOptions.<init>(MongoOptions.java:29)
        at com.mongodb.Mongo.<init>(Mongo.java:148)
        at com.mongodb.Mongo.<init>(Mongo.java:137)
        at com.sfatandrei.db.MongoManager.<init>(MongoManager.java:28)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.
    java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
        ... 84 more

mvn 의존성 : tree -Dverbose

[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ mongodb-performance-test ---
[INFO] com.sfatandrei:mongodb-performance-test:war:1.0
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO] |  \- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO] |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-asm:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  \- (org.springframework:spring-asm:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO] |     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-aop:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-webmvc:jar:3.1.1.RELEASE:compile
[INFO] |  +- (org.springframework:spring-asm:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-expression:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  \- (org.springframework:spring-web:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.0.0.RELEASE:compile
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-expression:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework.data:spring-data-commons-core:jar:1.2.0.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-tx:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.mongodb:mongo-java-driver:jar:2.7.1:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.springframework:spring-test:jar:3.1.1.RELEASE:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.mongodb:bson:jar:2.3:compile
[INFO] \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.6:compile
[INFO]    \- org.codehaus.jackson:jackson-core-asl:jar:1.9.6:compile

나는 jdk 7, tomcat 7.0.27, maven 3.0.3을 사용하고 있습니다.

해결법

  1. ==============================

    1.바이트 코드 수준의 오류처럼 보입니다. 어쩌면 tomcat 서버에 동일한 라이브러리의 두 가지 버전이있을 수 있습니다.

    바이트 코드 수준의 오류처럼 보입니다. 어쩌면 tomcat 서버에 동일한 라이브러리의 두 가지 버전이있을 수 있습니다.

    java.lang.IncompatibleClassChangeError의 원인은 무엇입니까?

  2. ==============================

    2.JBoss에서이 문제가 발생하면 JBoss가 RESTeasy REST 구현을 기본으로 제공하기 때문에 문제가 발생할 가능성이 큽니다. 독자적인 REST 라이브러리를 EAR / WAR 파일에 패키지하는 경우 배포 된 라이브러리가 작동하도록 기본 RESTeasy를 비활성화해야합니다.

    JBoss에서이 문제가 발생하면 JBoss가 RESTeasy REST 구현을 기본으로 제공하기 때문에 문제가 발생할 가능성이 큽니다. 독자적인 REST 라이브러리를 EAR / WAR 파일에 패키지하는 경우 배포 된 라이브러리가 작동하도록 기본 RESTeasy를 비활성화해야합니다.

  3. from https://stackoverflow.com/questions/10474976/java-lang-incompatibleclasschangeerror-implementing-class-mongo by cc-by-sa and MIT license