JEE6: What can be injected with @Resource?

JSR-250 (Common Annotations for the Java platform) addresses the runtime behavior of a container when processing classes with the Resource annotation; the relevant section is 2.3, which discusses the Resource annotation.

JSR-250 (Common Annotations for the Java platform) addresses the runtime behavior of a container when processing classes with the @Resource annotation; the relevant section is 2.3, which discusses the @Resource annotation. By and large, any resource that can be present in a deployment descriptor as a env-entry, service-ref, resource-ref, message-destination-ref or a resource-env-ref can be annotated with @Resource annotation for injection. The list of specific Java types whose instances can be injected into supported classes is also specified in the same section, and is reproduced 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 Note the last item in the table - according to the specification, any administered object associated with a resource, that is present in the JNDI directory can be injected. A definite list of such classes whose instances must be injected by a container, can be obtained from Chapter 5 of the Java EE 6 Platform Specification. This is not tabulated in any form, but nevertheless, the chapter specifies how an application developer must request for injection of any significant resource.

Most resources listed in the chapter are injected by specifying the @Resource annotation, or an another annotation that is used explicitly for that resource. The EJB 3.1 specification may repeat the contents of afore mentioned chapter 5 of the platform specification, for resources specific to the EJB container. The relevant details are in chapter 16 titled "Enterprise Bean Environment", with the relevant details being present in sub-sections titled "Bean Provider's Responsibilities".

With respect to the Servlet 3.0 Specification, the relevant details may be found in Section 15.5.4 which discusses the @Resource annotation semantics for a servlet container.

Thanks, great start. I learned from a book that I can also inject javax.ejb. EJBContext, javax.ejb.

SessionContext into EJBs. A servlet can receive javax.servlet. ServletContext ... How would I find out where this ends?

– Hank Aug 31 at 13:04 @Hank, I believe that is specified in the Java EE 6 platform specification at the very least. If not in the Java EE 6 specification, it would be present in the EJB 3.1 specification (Chapter 16) or the Servlet 3.0 specification (Section 15.5). – Vineet Reynolds Aug 31 at 14:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions