异步Http客户端 - 如何使用

时间:2014-09-25 09:01:16

标签: java exception client asynchttpclient

我正在使用https://github.com/AsyncHttpClient/async-http-client中的示例代码,并且我正在尝试创建GET请求:

package asyncHttpClient;

import com.ning.http.client.*;
import java.util.concurrent.Future;

public class AsyncHttpClientExchange {

    public static void main(String[] args) throws Exception {

        AsyncHttpClient client = new AsyncHttpClient();
        Future<Response> f = client.prepareGet("http://www.ning.com/").execute();
        Response r = f.get();
        System.out.println(r);
        client.close();

    }

}

当我尝试从我的日食中启动它时,我收到了这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.ning.http.client.AsyncHttpClient.<clinit>(AsyncHttpClient.java:152)
    at asyncHttpClient.AsyncHttpClientExchange.main(AsyncHttpClientExchange.java:10)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

我的日食或代码有问题吗? 我能做什么?非常感谢。

1 个答案:

答案 0 :(得分:2)

您的课程路径缺少slf4j。您可以从http://www.slf4j.org/download.html

下载一个

我使用Maven构建系统,将其添加到dependencies

pom部分
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>