I'm using Jetty 9.1 and Jersey 2.5.1. Jersey has built-in support for Jetty, so I start my server like that:
public static void main(String[] args) {
URI baseUri = UriBuilder.fromUri("http://localhost/").port(8080).build();
ResourceConfig config = ResourceConfig.forApplicationClass(MyApplication.class);
Server server = JettyHttpContainerFactory.createServer(baseUri, config);
}
MyApplication simply calls this.packages(...)
to lookup my REST api classes.
However, the REST api class contains a @Inject
annotated field, which should be injected by WELD. Obviously WELD is not started (CDI support not enabled), and weirder, it looks like HK2 (used by Jersey 2) is trying to perform the injection.
(I have a org.glassfish.hk2.api.UnsatisfiedDependencyException
when hitting the REST endpoint).
How do I setup correctly WELD (preferably programmatically)?