Reputation: 11482
I'm wondering if I have a remote interface MyService
and the corresponding implementation EJB MyServiceBean
whether I still can inject a bean instance using the @EJB
annotation into other ejbs or managed beans from jsf running on the same application server.
If this is the case, do I have to put the annotation on the interface or on the implementation? E.g:
@EJB
private MyService myService;
or
@EJB
private MyServiceBean myService;
Upvotes: 1
Views: 1356
Reputation:
It doesn't matter how do you obtain references @EJB
of local or remote enterprise beans. Use annotation
@EJB
ExampleBean exampleBean;
Upvotes: 0
Reputation: 20691
If you're accessing the EJB from a client within the same JVM as the EJB, the Remote interface is needless. The Remote interface is used by EJB clients that reside outside of the JVM in which the EJB is deployed. So in your particular case, all you'll need is
@EJB
private MyServiceBean myService;
Using the remote interface injection mechanism in your case would result in a needless roundtrip to arrive at the same result.
The use case for the different EJB invocation modes are
@Remote
: Denotes a remote business interface. Method parameters are passed by value
and need to be serializable as part of the RMI protocol.(cited from Apress' beginning Java EE6 Platform)
@Local
: Denotes a local business interface. Method parameters are passed by reference
from the client to the bean.(cited from Apress' beginning Java EE6 Platform)
None: This is the plain injection type where no interface is specified. Within the same JVM as the EJB, this is fine. From a design point of view (Loose coupling principle), you may want to use the @Local
injection method
Upvotes: 2