3

I have a project using Jersey v2.25.1. I was using Jersey's inbuilt HK2 injection to perform dependency injection, and everything worked fine. Fast forward to now, I decided to update to Jersey v2.27.

When I ran my project, I got the following exception:

java.lang.IllegalStateException: InjectionManagerFactory not found

After some googling, I found that I needed to add the jersey-hk2 dependency. Doing so made me get the following exception:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=<MyClass>,parent=<MyClass>,qualifiers={},position=0,optional=false,self=false,unqualified=null,1044705957)

Upon reverting all my dependencies to Jersey v2.25.1, everything works fine. What do I need to do to fix these errors, so I can use Jersey v2.27?

Edit: I don't use Maven so I can't really post a pom.xml, but tommorow I will put together an MVCE with the exact dependencies I have, and a basic example of Dependency Injection.

vikarjramun
  • 1,042
  • 12
  • 30
  • Please show your code for better help. It is not possible to for us to figure out what's going on with out it. Try providing a [MCVE]. – Paul Samsotha Jul 06 '18 at 20:43
  • @PaulSamsotha This isn't really a code problem, more of a config problem. I just need to figure out what configuration I need (extra dependencies, maybe) to make this run. I will post an MVCE tommorow, although it will probably be difficult as I don't use Maven (that's a different story altogether) – vikarjramun Jul 06 '18 at 23:09
  • It _is_ a code problem because there are breaking changes related to dependency injection starting from version 2.26. – Paul Samsotha Jul 06 '18 at 23:13
  • @PaulSamsotha Okay, I will post an MVCE as soon as I can. Thanks – vikarjramun Jul 06 '18 at 23:14
  • @PaulSamsotha For now, here is my current code - my [abstract binder - line 58](https://github.com/ArjMart/API/blob/d3ef41a858cf22a0c58da94cf5fdb42c3fe5313b/src/com/arjvik/arjmart/api/Hk2Feature.java#L58) and my [injection point - line 30](https://github.com/ArjMart/API/blob/d3ef41a858cf22a0c58da94cf5fdb42c3fe5313b/src/com/arjvik/arjmart/api/ETagFilter.java#L30). This shows how I bind one single interface and implementation, then inject it into a filter. – vikarjramun Jul 06 '18 at 23:25
  • 1
    Try to change your `AbstractBinder` import. There are two, a Jersey one and an HK2 one. Try to use the Jersey one. – Paul Samsotha Jul 06 '18 at 23:33
  • @PaulSamsotha Thank you so much!! If you mark that as an answer, I would happily accept it! --FYI, the API is a bit different, for example the `bindFactory` method now requires a `java.util.function.Supplier` instead of the old HK2 `Factory` – vikarjramun Jul 07 '18 at 00:08
  • 1
    You can go ahead and answer your own question. Just post what changes you made. I'm too lazy. – Paul Samsotha Jul 07 '18 at 03:37

1 Answers1

5

Answer by Paul Samsotha in a comment:

Try to change your AbstractBinder import. There are two, a Jersey one and an HK2 one. Try to use the Jersey one.

Basically, I needed to change the AbstractBinder class I implemented from

org.glassfish.hk2.utilities.binding.AbstractBinder

to

org.glassfish.jersey.internal.inject.AbstractBinder

The difference is that Jersey decoupled HK2 from it's internal DI mechanism in version 2.26, and thus, I needed to use the new AbstractBinder import, which comes directly from Jersey, and not HK2.

There are a few API differences: for instance, instead of a Factory<T>, bindFactory() takes a java.util.function.Supplier<T>.

vikarjramun
  • 1,042
  • 12
  • 30