users@glassfish.java.net

_at_Resource annotation in detail

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Jun 2010 07:14:59 PDT

I have looked through the Java EE 6 specification and have a few questions about the @Resource annotation.

Like many developers, I am quite comfortable with this usage:
[code]
@Resource
private SomeConnectionFactory myCF;
[/code]

And I also understand the new-to-Java-EE "lookup" attribute:
[code]
@Resource(lookup = "java:app/env/TheFactory")
private SomeConnectionFactory myCF;
[/code]

I realize I actually am drawing a blank on when one would actually use the "name" attribute:
[code]
@Resource(name = "something/relative/to/comp/env/perhaps/TheFactory")
private SomeConnectionFactory myCF;
[/code]

I'm asking because (as many of you are painfully aware...sorry about that) I'm still trying to hook up my Drools resource adapter (which you'll recall, maybe, is inside an .ear file with my EJBs that use it).

I've created a connection pool, and a connection resource for my ResourceAdapter, and had to give it a name as part of the latter step. I chose "ra/RulesEngine". But of course my source code doesn't refer to "ra/RulesEngine" anywhere, and, I would think, nor should it.

I hope someone can point me at the obvious place I missed that gives a detailed rundown of how the @Resource annotation (in source code land) interacts with the application environment (in application server land).

Thanks,
Laird
[Message sent by forum member 'ljnelson']

http://forums.java.net/jive/thread.jspa?messageID=475691