By using HK2's guice-bridge
I managed to integrate Jersey 2.x with Guice 3.x.
public class MyApp extends ResourceConfig {
@Inject
public MyApp(ServiceLocator serviceLocator) {
packages("com.mycompany");
...
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(GuiceContext.INJECTOR);
}
}
But now my Jersey tests don't work anymore.
public abstract class AbstractJerseyTest extends JerseyTest {
public AbstractJerseyTest() throws TestContainerException {
super(new InMemoryTestContainerFactory());
}
protected Application configure() {
new MyApp(); // ERROR: missing 'ServiceLocator'
}
}
So where do I get a ServiceLocator
for my unit tests?
We made it work with the help of Groovy:
It's not pretty, but it works.