-
Notifications
You must be signed in to change notification settings - Fork 630
Description
Describe the bug
We're using swagger to create interfaces for our rest services. These interfaces already contain all necessary JAX-RS annotations, that's why the implementation classes do not need/want to repeat them.
If such a REST service now tries CDI Injection of EJBs or other beans, the injection does not work and the property is still null when the service is called. The registration as REST service did complete successfully as we can see it being called.
The issue started when we where switching from javaee-7.0 to jakartaee-10.0.
Steps to Reproduce
Use the jakartaee-10.0 feature in openliberty.
Create an Interface & JAXRS service:
import jakarta.ws.rs.*;
@Path("/clock")
public interface ClockService {
@GET @Path("/now") @Produces({ "application/json" })
public Response getTimestamp();
}
---
import jakarta.ws.rs.*;
import jakarta.inject.Inject;
public class ClockServiceIml implements ClockService {
@Inject
private TimeService timeService;
public Response getTimestamp(){
return Response.ok(timeService.getTime());
}
}Variations:
- We tried to inject
@Statelesssession beans and@NamedCDI beans, the result was alwaysnull - Repeating the
@Pathannotation from the Interface in the implementation class this resolve the issue (however this would introduce duplicates between the swagger file and the code which can easily cause conflicts and hard to track bugs)
@Path("/clock") // injected service is no longer null
public class ClockServiceIml implements ClockService {- making the JAXR-RS resource a
@Statelesssession bean resolved the injection issue too, at the cost of having to now make all jars an EJB module.
@Stateless // injected service is no longer null
public class ClockServiceIml implements ClockService {- Specifically marking the JAX-RS resource with
@Namedstill resulted in NPE.
@Named // still NPE on the injected service
public class ClockServiceIml implements ClockService {Expected behavior
The TimeService should be injected and I can call methods on it.
Diagnostic information:
- OpenLiberty Version: 26.0.0.2
- Affected feature(s) jakartaee-10.0
- Java Version: openj9-17
Additional context
OpenLiberties documentation https://openliberty.io/docs/latest/jaxrs-integration-cdi.html on JaxRs and CDI does not show any evidence as to why this should not work.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status