web-dev-qa-db-ja.com

java.lang.IncompatibleClassChangeError:クラスMongoの実装

このエラーが発生する理由がわかりません。冗長なライブラリなどをクリーンアップしてみました。

実行しようとするとエラーが発生します:

  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 dependency: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を使用しています。

18
Andrei Sfat

これは、バイトコードレベルのエラーのようです。たぶん、Tomcatサーバーに同じライブラリの2つのバージョンがあります。

参照: Java.lang.IncompatibleClassChangeErrorの原因は?

19
James Gan

JBossでこの問題が発生した場合、JBossはRESTeasy REST実装をデフォルトとしてバンドルしているため、独自のRESTライブラリをEAR/WARファイルでは、デプロイされたライブラリが機能するためにデフォルトのRESTeasyを無効にする必要があります。

2
Zds