The @Resources annotation makes it possible to define resources that you are going to lookup at runtime. The example describes a way to lookup a data source 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 { public List getItems() { DataSource shoppingCartDB = (DataSource) ctx.lookup("ShoppingCartDB"); Connection conn = shoppingCartDB.getConnection(): return null; } }
Posted December 18, 2014