I am developing an application that uses Jersey (2.5) as its REST interface, and Jetty as an embedded HTTP (S) server, using the so-called "embedded" method, for example. without resorting to creation .warand deployment, but through the software configuration of handlers, resources, injections ...
I would like to somehow override HK2 ServiceLocator, which is used on the server side by Jersey, or perhaps provide this service locator with a parent to resolve dependencies that are defined outside of the REST part of the application. From what I see in the code, this is not possible: a ServiceLocator is created internally ApplicationHandlerby a call Injections:
if (customBinder == null) {
this.locator = Injections.createLocator(new ServerBinder(application.getProperties()), new ApplicationBinder());
} else {
this.locator = Injections.createLocator(new ServerBinder(application.getProperties()), new ApplicationBinder(),
customBinder);
}
And the code in Injections tells me the following:
public static ServiceLocator createLocator(Binder... binders) {
return _createLocator(null, null, binders);
}
which means that the newly created service locator has some kind of randomly generated name and does not have a parent.
Is there a (clean) way to change this behavior so that I introduce my own ServiceLocator as the application parent?
source
share