The Dependency Injection (DI) is a functionality for the EJB container to automatically set the reference to EJB and resource by specifying annotations (@EJB, @Resource and @Inject) in a field or the set method of the target class.
Among the classes running on the EJB container, following are the classes that become target classes:
Among the classes running on the Web container, following are the classes that become target classes:
When executing DI for referencing the Enterprise Bean home interface or business interface, specify @EJB.
When specifying @Resource, you can execute DI for the types of resources described in the following table.
Table 2-31 Resource types for which DI can be executed with @Resource
Resource type | Permission of DI#1 |
---|---|
java.lang.String#2 | N |
java.lang.Character#2 | N |
java.lang.Integer#2 | N |
java.lang.Boolean#2 | N |
java.lang.Double#2 | N |
java.lang.Byte#2 | N |
java.lang.Short#2 | N |
java.lang.Long#2 | N |
java.lang.Float#2 | N |
javax.xml.rpc.Service | N |
javax.xml.ws.Service | N |
javax.jws.WebService | N |
javax.sql.DataSource#3 | Y |
javax.jms.ConnectionFactory | Y |
javax.jms.QueueConnectionFactory#4 | Y |
javax.jms.TopicConnectionFactory | Y |
javax.mail.Session | Y |
java.net.URL | N |
javax.resource.cci.ConnectionFactory#5 | Y |
org.omg.CORBA_2_3.ORB | Y#6 |
javax.jms.Queue#3, #7 | Y |
javax.jms.Topic#7 | Y |
javax.resource.cci.InteractionSpec | N |
javax.transaction.UserTransaction | Y#8 |
javax.ejb.EJBContext | Y#9 |
javax.ejb.SessionContext | Y#9 |
javax.ejb.TimerService | Y#9, #10 |
JavaBeans resource | Y |
Interface unique to the object to be managed | Y |