I searched for some time in SO and official documentation, but I did not find a way to directly use CDI injection in the JAX-RS client.
I retrieve the client using the builder method, and I want to register WriterInterceptor(or any filter-like component) that uses injection to retrieve another bean.
I want to use CDI injection and not register every bean with HK2.
ClientBuilder.newBuilder()
.register(MyWriter.class)
.build();
And MyWriter with the introduced class.
@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 {
}
I am launching an integrated jetty with Jersey 2 and Weld SE.
source
share