@Resources

Javadoc

The @Resources annotation makes it possible to define resources that you are going to lookup at runtime in your EJB. The example describes a way to lookup a datasource that is mentioned in the @Resources annotation on the class.

  @Resources(value={
    @Resource(name="ShoppingCartDB", type=javax.sql.DataSource),
    @Resource(name="ShoppingCartMail", type=javax.mail.Session)
  })
  @Stateful
  public class ShoppingCartBean {

    @Resource
    SessionContext ctx;

    public List getItems() {
      DataSource shoppingCartDB = (DataSource) ctx.lookup("ShoppingCartDB");
      Connection conn = shoppingCartDB.getConnection():
      return null;
    }
  }