aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Class/Type level resource annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Class/Type level resource annotation" Watch "Class/Type level resource annotation" New topic
Author

Class/Type level resource annotation

aze opuiy
Greenhorn

Joined: Dec 03, 2010
Posts: 4
Hello,

I don't understand the aims of the Class/Type level resource annotation.

Why to declare a Class/Type level resource annotation :



When it is working without :




Could someone explain to me the difference and the goal of the class level resource annotation ?
Thank you by advance for your help.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29230
    
135

Per Oracle,
The container will inject the resource referred to by @Resource into the component either at runtime or when the component is initialized, depending on whether field/method injection or class injection is used.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
aze opuiy
Greenhorn

Joined: Dec 03, 2010
Posts: 4
Thank you for your answer.

What is the difference between runtime and "when the component is initialized" ?
The component is not initialized at runtime ??

I am sorry but i don't understand.

I understood that, during the deployment, "injected resource" is binding in the ENC of managed bean with the path declared by the attribute name => java:/comp/env/[name]
And that during execution, the resource is accessible (with injection or direct access) via the ENC entry.

But i don't understand the goal of the class level annotation (and so the goal of the <resource-ref>).

I you want use directly JNDI and if you do not declare class level annotation, you will have not entry in the ENC but you can lookup to the global JNDI, no ?

I am sure i missed something...

Thank you for your help
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29230
    
135

Yes, you can always directly use JNDI.

I think they are trying to say the difference is between when the component is initialized vs when the injected resources is actually referred to.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class/Type level resource annotation
 
Similar Threads
Doubt with DI & JNDI
The place where we define Annotations inside the EJB Bean class
JNDI issue
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"