@Resource (lookup="jms/websendqueue")
Queue queue;
@MessageDriven( ... mappedName="jms/websendqueue")
....
@Resource annotation elements:
name - besides performing an injection, the @Resource annotation implicitly creates a binding referring to the injected resource in the java:comp namespace. This is primarily done for backward compatibility. This attribute allows you to specify the name that is used for the implicit binding. This is equivalent t the <res-ref-name> element in deployment descriptors used extensively in EJB2.
lookup - This is the actual JNDI lookup name of the resource to be injected. This is likely the attribute you will use the most.
1. @Resource (lookup="java:global/jdbc/ActionBazaarDB")
private DataSource dataSource;
2. @Resource (lookup="java:global/jms/ActionBazaarQueue")
private Queue queue;
3. @Resource (lookup="java:global/mail/ActionBazaar")
private javax.mail.Session mailSession;
@Resource
private EJBContext context;
Note that the injected session context isn't stored anywhere in JNDI. In fact, it would be incorrect to try to specify JNDI lookup parameters in this case at all, and servers will probably ignore the element if specified.
mappedName - A vendor-name for the bean.
The connection factory was created by the server GlassFish in this case, with the name jms/SalutationQueueFactory which is of type QueueConnectionFactory.
@Resource (mappedName ="jms/SalutationQueueFactory")
private QueueConnectionFactory queueConnectionFactory;
The queue is of type javax.jms.Queue and used the name jms/SalutationQueue as defined within the server. @Resource annotation was used again to inject this resource.
@Resource(mappedName="jms/SalutationQueue")
private Queue queue;
mappedName
The EJB 3.0 Specification defines mappedName as a "product-specific name that the session bean should be mapped to." Often, application server use mappedName to map a session bean to a global JNDI name. The EJB 3.1 specification sort of deprecates the mappedName element and introduces the concept of "portable global JNDI name".
So, is lookkup a replacement of mappedName?
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|