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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.