Local and remote interfaces

By default, an EJB is always local. A local EJB can be invoked only inside the same deployment package. A good coupling for the local EJB is the CDI injection. In previous paragraphs, we used the @Inject annotation to inject the EJB. It is only possible if the EJBs are local.

The annotation that represents a local EJB is @Local. Our EJB, by default, can be seen as annotated with it:

@Singleton@Localpublic class MyPosts {...}

The remote EJB can be invoked by a different deployment package through JNDI. Here is an implementation of remote EJB:

@Singleton@Remotepublic class MyHarderPosts {...}

When we deploy a remote EJB, WildFly automatically creates three RMI stubs named through a JNDI name. Here is a sample of ...

Get Mastering Java EE Development with WildFly now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.