jersey - 在 Dropwizard 应用程序中将 http 客户端注册到 jersey 环境时无法解析符号ExternalServiceResource

标签 jersey httpclient dropwizard jersey-client

我正在 Dropwizard REST 应用程序中实现 Dropwizard 客户端。 我正在关注他们的User Manual .

尝试将客户端注册到 Jersey 环境时但找不到类ExternalServiceResource

@Override
public void run(ExampleConfiguration config,
            Environment environment) {
final HttpClient httpClient = new HttpClientBuilder(environment).using(config.getHttpClientConfiguration())
                                                                .build();
environment.jersey().register(new ExternalServiceResource(httpClient));
}

最佳答案

我认为ExternalServiceResource是一个例子,但它看起来像:

@Path("/your/path")
public class ExternalServiceResource {

    private final HttpClient client;

    public ExternalServiceResource(HttpClient client) {
        this.client = client;
    }

    @GET
    public String doStuff() {
        return /* use client to make some call */;
    }
}

您可以输入任何您想要的名称。创建资源的唯一要求是 @Path 注释,您必须将其放在类级别,以及一些方法 @GET、@POST...

关于jersey - 在 Dropwizard 应用程序中将 http 客户端注册到 jersey 环境时无法解析符号ExternalServiceResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30914683/

相关文章:

angular - 如何在 Angular 的 HttpClient 中使用 reportProgress?

java - 将委托(delegate)人注入(inject) Jersey 2 中的资源方法

java - 如何使用 Java SE 6 的内置 Web 服务器运行 Jersey?

java - 如果我们在指定时间内没有收到响应,如何关闭 API 连接

java - 如何从 Dropwizard 资源中的 config.yml 文件获取字符串?

dropwizard - 基于Java 8的可选QueryParam的简单Dropwizard 0.7.1应用失败

java - 传递自定义类型查询参数

java - Spring 更改 Content-Type 的 header ?

java - 使用 Jersey、jaxb 和 jax-rs 时如何设置 xml 命名空间

java - 有时必须等待很长时间,直到 HttpClient.execute() 抛出异常