Accessing session beans using dependency injection

You can access session beans either using the @EJB annotation (which injects the bean in the client class) or by performing the Java Naming and Directory Interface (JNDI) lookup. EJB containers are required to make JNDI URLs of the EJBs available to clients.

Injecting session beans using @EJB works only for managed components, that is, components of the application whose life cycle is managed by the EJB container. When a component is managed by the container, it is created (instantiated) and destroyed by the container. You do not create managed components using the new operator. JEE-managed components that support direct injection of EJBs are servlets, managed beans of JSF pages, and EJBs ...

Get Java EE 8 Development with Eclipse 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.