【发布时间】:2017-04-22 01:20:37
【问题描述】:
我在 SO 和官方文档上搜索了一段时间,但找不到直接将 CDI 注入 JAX-RS 客户端的方法。
我使用 builder 方法检索客户端,并且我想注册一个 WriterInterceptor(或任何类似过滤器的组件),它使用注入来检索另一个 bean。
我想使用 CDI 注入并避免向 HK2 注册每个 bean。
ClientBuilder.newBuilder()
.register(MyWriter.class)
.build();
MyWriter 和注入的类。
@Provider
public class MyWriter implements WriterInterceptor {
private final MyRepo repo;
@Inject
public MyWriter(MyRepo repo) {
this.repo = repo;
}
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
context.proceed();
}
}
public class MyRepo {
}
我正在使用 Jersey 2 和 Weld SE 在嵌入式码头中跑步。
【问题讨论】:
标签: jersey jax-rs cdi embedded-jetty weld