2012-05-06 41 views
17

我無法弄清爲什麼我得到這個錯誤。我試圖清理冗餘的庫,等等。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。

+1

通常,該錯誤是由於使用一組JAR文件編譯並針對不同的集合運行所致。它可以是您的班級或您使用的其中一個JAR中的某個班級。不幸的是,它似乎沒有告訴我們哪個班級發生了錯誤。 –

+0

@HotLicks,實際上它說哪個類發生錯誤:'at com.mongodb.MongoOptions.reset(MongoOptions.java:47) ' – sfat

+1

不,這就是發生錯誤的地方。但是錯誤發生在正在加載的類上,無論如何。如果你可以在那個時候檢查代碼,你可能會破譯正在加載的類。 –

回答

19

這看起來像是字節代碼級別的錯誤。也許你在你的tomcat服務器上有兩個版本的同一個庫。

參見:What causes java.lang.IncompatibleClassChangeError?

+2

似乎'mongo-java-driver'裏面有一個使用org.bson的類,我添加了自己的'bson'依賴項,這是干擾 – sfat

1

如果你的JBoss下這個問題,這是最有可能的原因在於JBoss的捆綁RestEasy的REST實現爲默認的事實。如果您將自己的REST庫打包爲EAR/WAR文件,則需要禁用部署庫的默認RESTeasy才能工作。

相關問題