I would like to create a singleton instance of a class that is not involved in Jersey as a resource or service, and still want its dependencies to be injected from Jersey customer service.
I can register this class manually in my ResourceConfig constructor, then the ResourceConfig is passed to the Grizzly factory method, for example:
ResourceConfig resourceConfig = new DeviceServiceApplication(); LOGGER.info("Starting grizzly2..."); return GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, mServiceLocator);
The problem remains how to get a link to the ServiceLocator service in Jersey so that I can call createAndInitialize () to get my object with nested dependencies. I see that in versions of previous versions there were constructor options that expect ApplicationHandler, which, of course, provides access to the service locator (how I initialize this is another matter). You can also see that I tried passing in the parent ServiceLocator, but, of course, the resolution comes from child-> parent locator, and not in the other direction, so the parent request for my object is not executed, because the Jersey types are @Contract and @Service are not visible here.
Do I need to use something other than GrizzlyHttpServerFactory? I refuse and manually connect my singleton dependencies?
source share