I am trying to initialize some components in a Jersey application in the Application constructor (a thing that inherits from ResourceConfig). Looks like this
public Application(@Context ServletContext context, @Context ServiceLocator locator)...
When I try to use the locator at any time, I still cannot instantiate the things that I registered with AbstractBinder using the locator.create (MyThing.class) method.
I am sure that they are connected correctly because they are correctly injected into my resource classes through the annotation of the @inject field.
The difference is that the Jersey / HK2 structure creates instances of my resource classes (as expected, since they are in the package scan path), but I cannot use ServiceLocator with the code.
My ultimate goal is to introduce other non-standard classes if they have the @Inject attribute, for example. I have a working class that needs to enter a configured database access level. I want to say
locator.Create(AWorker.class)
and enter it.
How to get a real ServiceLocator that will enter everything that I have already registered / associated with my Binder? (Or should I use something other than ServiceLocator?)
source share