Setter injection methods are invoked by the container before any business methods
on the bean instance. Multiple resources may be injected using the @Resources
annotation. For example, in the following code snippet two resources of type javax.
sql.DataSource are injected.
JNDI resources injected with the dependency mechanism may be looked up in the
java:comp/env namespace. For example, if the JNDI name of a resource of type
javax.sql.DataSource is catalogDB , the resource may be looked up as follows.
InitialContext ctx = new InitialContext();
Javax.sql.DataSource ds = ctx.lookup("java:comp/env/catalogDB");
Simplified Session Beans
In EJB 2.x, a session bean is required to implement the SessionBean interface. An
EJB 3.0 session bean class is a POJO ( Plain Old Java Object ) and does not implement
the SessionBean interface.
An EJB 2.x session bean class includes one or more ejbCreate methods, the callback
methods ejbActivate , ejbPassivate , ejbRemove , and setSessionContext , and
the business methods defined in the local/remote interface. An EJB 3.0 session bean
class includes only the business methods.
In EJB 3.0, EJB component interfaces and home interfaces are not required for
session beans. A remote interface in an EJB 2.x session EJB extends the javax.ejb.
EJBObject interface; a local interface extends the javax.ejb.EJBLocalObject
interface. A home interface in an EJB 2.x session EJB extends the javax.ejb.EJBHome
interface; a local home interface extends the javax.ejb.EJBLocalHome interface. In
EJB 3.0 the home/local home and remote/local interfaces are not required. The EJB
interfaces are replaced with a POJI ( Plain Old Java Interface ) business interface.
If a business interface is not included with the session bean class, a POJI business
interface gets generated from the session bean class by the EJB server.
An EJB 2.x session EJB includes a deployment descriptor that specifies the EJB name,
the bean class name, and the interfaces. The deployment descriptor also specifies
the bean type of Stateless/Stateful. In EJB 3.0, a deployment descriptor is not
required for a session bean. An example EJB 2.x session bean, which implements the
SessionBean interface, is listed next: