I'm trying to updating my Jersey project from 2.25 to 2.27.
Jersey is part of Java EE 8 since version 2.26, so I've also decided to update my project from Java EE 7 to Java EE 8, and from JAX-RS 2.0/CDI 1.x/Weld2.x/Apache Tomcat 8 to JAX-RS 2.1/CDI 2.0/Weld 3.0/Apache Tomcat 9.
The problem is I can't figure out the exact dependencies I need to include in my project (Maven project, pom.xml
).
Things that I've tried:
- I've followed intructions on this answer to install Weld on Tomcat
- The latest Jersey documentation doesn't seem to cover this case. Anyway, I've tried to mimic the dependencies included in the CDI webapp example
- Weld 2.4 to 3.0 migration guide
- ...and finally, in my despair, different combinations of the following dependencies:
cdi-api
,jersey-hk2
,javax.inject
,jersey-cdi1x
,jersey-cdi1x-servlet
,weld-servlet
,weld-servlet-core
,weld-servlet-shaded
,weld-core-impl
These are my current dependencies (pom.xml
):
<!-- Java EE -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${java-ee.version}</version>
</dependency>
<!-- JAX-RS -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- CDI (Jersey HK2 / Weld) -->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>${weld.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
<version>${weld.version}</version>
</dependency>
And this is the error I'm currently getting when trying to inject a @Singleton
into my resource (@Path
):
ADVERTENCIA: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
...
GRAVE: El Servlet.service() para el servlet [CGERestApplication] en el contexto con ruta [/igea-cge-interfaces] lanzó la excepción [A MultiException has 3 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=SapClient,parent=CambioEstadoTrabajoService,qualifiers={},position=-1,optional=false,self=false,unqualified=null,363959695)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of es.indra.isl.igea.external.cge.web.api.services.sap.CambioEstadoTrabajoService errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on es.indra.isl.igea.external.cge.web.api.services.sap.CambioEstadoTrabajoService
] with root cause:
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=SapClient,parent=CambioEstadoTrabajoService,qualifiers={},position=-1,optional=false,self=false,unqualified=null,363959695)
at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212)
at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:235)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)
at org.glassfish.jersey.inject.hk2.RequestContext.findOrCreate(RequestContext.java:83)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126)
at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:777)
at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:740)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:710)
at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getInstance(AbstractHk2InjectionManager.java:184)
at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getInstance(ImmediateHk2InjectionManager.java:54)
at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:129)
at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284)
at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:75)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:110)
And the Tomcat startup log:
jun 04, 2018 10:09:07 AM org.jboss.weld.environment.servlet.EnhancedListener onStartup INFO: WELD-ENV-001008: Initialize Weld using ServletContainerInitializer jun 04, 2018 10:09:08 AM org.jboss.weld.bootstrap.WeldStartup INFO: WELD-000900: 3.0.4 (Final) jun 04, 2018 10:09:08 AM org.jboss.weld.bootstrap.WeldStartup startContainer INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. jun 04, 2018 10:09:09 AM org.jboss.weld.environment.tomcat.TomcatContainer initialize INFO: WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.