Enterprise Java Development@TOPIC@
public class CdiDemoConfig {
@Produces
@CdiDemo
@PersistenceContext(unitName="cdi-config")-->-+
+-<--------public EntityManager em; <--------------------+
|
| public class ProjectsDaoImpl implements ProjectsDao {
| private EntityManager em;
|
+--------> @PersistenceContext @CdiDemo
public void setEntityManager(EntityManager em) {
this.em = em;
}
Public field used as injection source
Useful when no behavior is required
@Produces
@CdiDemo
+-<------ public JobsDao jobsDao(@CdiDemo EntityManager em) {
| JobsDaoImpl impl = new JobsDaoImpl();
| impl.setEntityManager(em);
| return impl;
| }
|
| @Stateless
| @Remote(JobsMgmtRemote.class)
| public class JobsMgmtEJB implements JobsMgmtRemote {
| @Inject @CdiDemo
+----------> private JobsDao jobDao;
Injection type was not ambiguous - no @Qualifier required
Method called by container
Method declares parameters for what it needs to build product
Method parameters automatically injected
@Resource(lookup="java:jboss/datasources/ExampleDS")
@Produces
public DataSource ds;
Injection source populated from a JNDI lookup
@EJB(lookup="java:app/jndiDemoEJB/CookEJB!ejava.examples.jndidemo.ejb.CookLocal")
@Produces |
@Cook |
+---<--public Scheduler cook; <-------------------------+
|
| @Stateless
| public class TrainSchedulerEJB
| @Inject @Any
`----> protected Instance<Scheduler> anyCook;
protected Scheduler cook2; |
+---------------+
v
cook2 = anyCook.select(new CookQualifier()).get();
public class CookQualifier extends javax.enterprise.util.AnnotationLiteral<Cook>{}
Allows bean to hold onto all implementations of type
Bean can select from different implementations at runtime
@Named
public class JPASchedulerDAOImpl extends JPADAOBase<Task> implements SchedulerDAO {
Assignable to four (4) different types
JPASchedulerDAOImpl
JPADAOBase<Task>
SchedulerDAO
java.lang.Object
@Typed({SchedulerDAO.class, JPASchedulerDAOImpl.class})
public class JPASchedulerDAOImpl extends JPADAOBase<Task> implements SchedulerDAO {
@Type reduces number of types allowed
JPASchedulerDAOImpl
SchedulerDAO
@Named("sellerController")
@ConversationScoped
public class SellerController implements Serializable {
<h3>Sell Products (#{sellerController.seller.name})</h3>
Used for document expression languages to reference intended bean