Java EE – jee6: what can @ resource inject?
I try to find out what can be injected into a stateless session bean through the @ resource annotation Where can I find a list? Does it depend on the container (GlassFish 3.1.1 in my case)?
Solution
Jsr-250 (common annotations for the Java platform) solves the runtime behavior of the container when using @ resource annotations to process classes; The related part is 2.3, which discusses the @ resource annotation
In general, the @ resource annotation can be used to annotate any resource that can exist in the deployment descriptor as env entry, service ref, resource ref, message destination ref or resource env Ref The list of specific Java types that can inject instances into supported classes is also specified in the same section and copied below:
Java Type Equivalent Resource type java.lang.String env-entry java.lang.Character env-entry java.lang.Integer env-entry java.lang.Boolean env-entry java.lang.Double env-entry java.lang.Byte env-entry java.lang.Short env-entry java.lang.Long env-entry java.lang.Float env-entry javax.xml.rpc.Service service-ref javax.xml.ws.Service service-ref javax.jws.WebService service-ref javax.sql.DataSource resource-ref javax.jms.ConnectionFactory resource-ref javax.jms.QueueConnectionFactory resource-ref javax.jms.TopicConnectionFactory resource-ref javax.mail.Session resource-ref java.net.URL resource-ref javax.resource.cci.ConnectionFactory resource-ref org.omg.CORBA_2_3.ORB resource-ref any other connection factory defined by a resource adapter resource-ref javax.jms.Queue message-destination-ref javax.jms.Topic message-destination-ref javax.resource.cci.InteractionSpec resource-env-ref javax.transaction.UserTransaction resource-env-ref Everything else resource-env-ref
Please note the last item in the table - according to the specification, any managed object associated with the resource that exists in the JNDI directory can be injected
An explicit list of these classes, whose examples must be injected by the container, can be obtained from Chapter 5 of the Java EE 6 platform specification This is not tabulated in any form, but this chapter specifies how application developers must request the injection of any important resources Most of the resources listed in this chapter are injected by specifying the @ resource annotation or another annotation explicitly used for the resource
For EJB container specific resources, EJB 3.1 specification can repeat the contents of Chapter 5 of the platform specification mentioned earlier See Chapter 16 "enterprise bean environment" for relevant details, which appear in the section entitled "responsibilities of bean provider"
For servlet 3.0 specification, please refer to section 15.5.1 for details Found in Section 4, which discusses the @ resource annotation semantics of servlet containers