Any resource in JNDI name space can be injected
into any container-managed object (servlet, enterprise bean, managed bean), usually of the type of an interface
NOT type safe, inject by name
field based / method based (method starts with "set", returns void, and accept only one parameter)
Resource annotation is in javax.annotation package
/* field based */
public class MyServlet extends HttpServlet {
@Resource(name="java:comp/DefaultDataSource")
private javax.sql.DataSource dsc;
...
}
-------------------------------------------------------------
/* method based */
public class MyServlet extends HttpServlet {
private javax.sql.DataSource dsc;
...
@Resource(name="java:comp/DefaultDataSource")
public void setDsc(java.sql.DataSource ds) {
dsc = ds;
}
}