我已經實現了http客戶端與我使用Apache CXF實現的其餘服務器進行通信。當我在瀏覽器中使用url時,evrything很好,但是當我使用客戶端時,我得到了一個異常。唯一的例外是實現一個客戶端來調用Rest Web服務
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:99) at org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:75) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:131) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:193) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at ABC.XYZ(ABC.java:45) at ABC.XYZ(ABC.java:93)
我已經寫了下面的代碼在我的客戶端
HttpClient client = HttpClientBuilder.create().build();
HttpGet getRequest = new HttpGet(path);
getRequest.addHeader("accept", "application/xml");
HttpResponse response = client.execute(getRequest);//here I have an exception
您如何運行客戶端代碼?看起來您的類路徑中有多個相互衝突的SLF4J版本。如果您發佈了某人可能幫助的類路徑,但目前沒有足夠的信息來回答您的問題 –
作爲主類 – Jerry
問題在於您的類路徑 - 您如何調用主類 - 通過命令行中的java,通過IDE等Eclipse,通過Ant?/Maven?/Gradle? –