@ejbgen:resource-ref Annotation

This tag maps a JNDI reference used within a bean to an external resource connection factory. Common examples of such connection factories are (JDBC) javax.sql.DataSource, (JMS) javax.jms.QueueConnectionFactory, and (JMS) javax.jms.TopicConnectionFactory.

Scope

Class tag on all EJBs.

Syntax

@ejbgen:resource-ref

auth="Application/Container"

[id="TagID"]

jndi-name="JNDIName"

name="ReferenceName"

[sharing-scope="Shareable/Unshareable"]

type="ResourceType"

Attributes

auth

Required. Specifies who is responsible for authentication to use the resource. Valid values are Application and Container.

id

Optional. Specifies the ID of the tag. For more information, see EJBGen Tag Inheritance.

jndi-name

Required. Specifies the JNDI Name of the referenced external resource.

name

Required. Specifies the name of the reference to the external resource as used in the bean definition.

sharing-scope

Optional. Specifies whether the resource connections can be shared by multiple EJBs in the same transaction or 'unit of work'. Valid values are Shareable and Unshareable. When left unspecified the default Shareable is used.

type

Required. Specifies the type of the resource. Examples are javax.sql.DataSource, javax.jms.QueueConnectionFactory, and javax.jms.TopicConnectionFactory.

Example

The following example shows the use of external resource and administered object references, and the mapping of these references using ejbgen:resource-ref and ejbgen:resource-env-ref tags in an EJB:

/** 

 * 
 * @ejbgen:resource-ref auth="Container"
 *   jndi-name = "weblogic.jws.jms.QueueConnectionFactory"
 *   name = "jms/QueueConnectionFactory"
 *   type="javax.jms.QueueConnectionFactory"
 * 
 * @ejbgen:resource-env-ref 
 *  jndi-name="MyQueue" 
 *  name="jms/MyQueue" 
 *  type = "javax.jms.Queue" 
 *   
 * ...
 */
public class SomeBean extends GenericSessionBean implements SessionBean
{
   private QueueConnectionFactory factory;
   private Queue queue;
   
   ... 

   try {
      javax.naming.Context ic = new InitialContext();
      factory = (QueueConnectionFactory) ic.lookup("java:comp/env/jms/QueueConnectionFactory");  
      queue = (Queue) ic.lookup("java:comp/env/jms/MyQueue");
   } 
   catch (NamingException ne) {
      ...
   }
   ...
}

Related Topics

@ejbgen:resource-env-ref Annotation

Tutorial: Enterprise JavaBeans