2016-05-27 4 views
0

Webサービスを呼び出すためにhttpClientを使用しています。コードは以下の通りである:SpringMavenでslf4j例外を解決する方法

public static void main(String args[]) { 

    if (connection!=null) { 

     String url = "some url"; 
    String result = null; 
    Statement statement = null; 
    HttpClient client = HttpClientBuilder.create().build(); 
    HttpGet requestFinal = new HttpGet(url); 
    requestFinal.addHeader("Connection", "Keep-Alive"); 
    requestFinal.addHeader("Content-Type", "application/xml"); 
    requestFinal.addHeader("Accept", "application/xml"); 

    HttpResponse responseFinal = null; 
    StringBuilder responseBuilderFinal = new StringBuilder(); 
    BufferedReader bufferedReader = null; 

    try { 
     responseFinal = client.execute(requestFinal); 
     int statusCode = responseFinal.getStatusLine().getStatusCode(); 

     statement = connection.createStatement(); 
     bufferedReader = new BufferedReader(new InputStreamReader(responseFinal.getEntity().getContent())); 
     String lines = ""; 
     while ((lines = bufferedReader.readLine()) != null) { 
      responseBuilderFinal.append(lines); 
     } 
     requestFinal.abort(); 
    } catch (IOException ioException) { 

     logger.error("HttpCall class third catch block---" + ioException); 
    }} 

日食がresponseFinal = client.execute(requestFinal);

line--実行すると、次のエラーを与える:

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) 

これで私を助けてください。前もって感謝します。

+0

slf4j jarがあなたのcalsspathにあることを確認してください。もしそうなら、nは戦争政策を親に最後に設定する。問題を解決します。 – Ahmed

+0

これは私のクラスパスにある。 mainメソッド(独立したJavaクラスとして)から実行すると問題が発生します。私は静的メソッドを作成し、ボタンイベントのfrontEndから呼び出すときに問題はありません。私はなぜそれが起こっているのかを知っています。 – Jag

答えて

0

プロジェクトで使用した互換性の問題は.jarです。

slf4j.jarの古いバージョンを使用しています。あなたの瓶は、先に発売された.jarsで置き換えてください。

新しい.jarを追加してプロジェクトをクリーンアップし、プロジェクトを再ビルドしてみてください。

ありがとうございました

関連する問題