I have an EAR file containing a WAR.
The EAR contains an EJB jar. The EJB exposes a Local and Remote interface.
@Stateless(name = "FooServiceEJB") @Local(IFooServiceLocal.class) @Remote(IFooService.class) public class FooServiceBean implements IFooService, IFooServiceLocal { ... }
The WAR file defines a JAXRS annotated class.
@Path("/foo") @LocalBean @Stateless public class FooResource { ... }
I wish to inject the local 'view' of the EJB into the JAXRS resource class. Apparently I have two options, which I assumed would be equivalent (for the most part):
- Use @EJB
- Use @Inject (To many, this appears to be the preferred option - see Should I use @EJB or @Inject)
I'm running JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14).
The difference in behaviour that I am seeing is as follows (on JBoss - haven't tried any other app servers):
If I use @EJB to inject the local ejb, then the call semantics are by reference (as expected). For example:
@EJB
private FooServiceLocal fooService;
However, if I use @Inject to inject the local ejb, the call semantics are by value (i.e. serialization occurs). For example:
@Inject
private IFooServiceLocal fooService;
Here's a snapshot of the thread stack with the class that I believe is performing the serialization. The thread stack is completely different when I use the @EJB annoation.
https://i.stack.imgur.com/BXSaz.png
Any ideas why I am seeing this difference in behaviour?