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

Che*_*tan 4 jersey httpclient dropwizard jersey-client

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

尝试将客户端注册到 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));
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*que 6

我认为 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 */;
    }
}
Run Code Online (Sandbox Code Playgroud)

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