Originally posted by Mihai Radulescu:
Which is the practical purpose for such a mapping ?
Consider this example - You have a
servlet which calls some (unmanaged) XYZ class which further calls a (unmanaged) MessageSender class which sends an message to a JMS queue. Its not advisable to keep passing the JMS queue from the servlet to the MessageSender class and the MessageSender is not a managed class so you can't even inject the queue. Instead, you inject the queue in the ENC of the servlet (as explained in the example above). Then later during the flow through the servlet, the MessageSender can lookup the queue in the servlet's ENC. You might ask me why not directly lookup the queue using the JNDI (mappedName) name from the MessageSender. If interested, see
this
This entire example is exactly what the resource-ref entry is meant to do through xml files.