Jersey stopped working with InjectionManagerFactory not found Jersey stopped working with InjectionManagerFactory not found java java

Jersey stopped working with InjectionManagerFactory not found


Add this dependency:

<dependency>    <groupId>org.glassfish.jersey.inject</groupId>    <artifactId>jersey-hk2</artifactId>    <version>2.28</version></dependency>

cf. https://stackoverflow.com/a/44536542/1070215

Make sure not to mix your Jersey dependency versions. This answer says version "2.28", but use whatever version your other Jersey dependency versions are.


Jersey 2.26 and newer are not backward compatible with older versions. The reason behind that has been stated in the release notes:

Unfortunately, there was a need to make backwards incompatible changesin 2.26. Concretely jersey-proprietary reactive client API iscompletely gone and cannot be supported any longer - it conflicts withwhat was introduced in JAX-RS 2.1 (that's the price for Jersey being"spec playground..").

Another bigger change in Jersey code is attempt to make Jersey coreindependent of any specific injection framework. As you might now,Jersey 2.x is (was!) pretty tightly dependent on HK2, which sometimescauses issues (esp. when running on other injection containers. Jerseynow defines it's own injection facade, which, when implementedproperly, replaces all internal Jersey injection.


As for now one should use the following dependencies:

Maven

<dependency>    <groupId>org.glassfish.jersey.inject</groupId>    <artifactId>jersey-hk2</artifactId>    <version>2.26</version></dependency>

Gradle

compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'


Here is the reason. Starting from Jersey 2.26, Jersey removed HK2 as a hard dependency. It created an SPI as a facade for the dependency injection provider, in the form of the InjectionManager and InjectionManagerFactory. So for Jersey to run, we need to have an implementation of the InjectionManagerFactory. There are two implementations of this, which are for HK2 and CDI. The HK2 dependency is the jersey-hk2 others are talking about.

<dependency>    <groupId>org.glassfish.jersey.inject</groupId>    <artifactId>jersey-hk2</artifactId>    <version>2.26</version></dependency>

The CDI dependency is

<dependency>    <groupId>org.glassfish.jersey.inject</groupId>    <artifactId>jersey-cdi2-se</artifactId>    <version>2.26</version></dependency>

This (jersey-cdi2-se) should only be used for SE environments and not EE environments.

Jersey made this change to allow others to provide their own dependency injection framework. They don't have any plans to implement any other InjectionManagers, though others have made attempts at implementing one for Guice.