2016-04-25 20 views
0

我使用org.apache.http.client從Tomcat 7調用POST。 相同的代碼在我的開發機器上工作,但失敗我的服務器。HttpClient沒有在Tomcat上工作,NoSuchMethodError org/apache/http/entity/ContentType

我似乎是一個類加載器的問題,但我雙重檢查了所有的罐子,並且他們的lib目錄中有相同的罐子。

java.lang.NoSuchMethodError: org.apache.http.entity.StringEntity.<init>(Ljava/lang/String;Lorg/apache/http/entity/ContentType;)V 
    org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:61) 
    org.botlibre.util.Utils.httpPOST(Utils.java:424) 

我傾倒了使用的罐子,並且兩個tomcat都使用相同的httpclient-4.2.5.jar和http罐子。

我的開發機具有的Tomcat 7.0.50和服務器7.0.68

CodeSource src = StringEntity.class.getProtectionDomain().getCodeSource(); 
if (src != null) { 
    System.out.println(src.getLocation()); 
} 
Class klass = StringEntity.class; 
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class"); 
System.out.println(location); 
+0

聽起來像一個依賴性的衝突,也許你有不同的版本重複的罐子,確保您所有的HttpClient庫都來自同一版本,並且沒有重複。 – vzamanillo

回答

1

好吧,這個問題是我的其他的lib罐子的人有它裏面的HttpClient類的另一個版本。出於某種原因,它使用相同的罐子在開發機器上工作,我想它會以不同的順序來挑選它們。

這是我如何調試它。

Class klass = ContentType.class; 
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class"); 
System.out.println(location);