File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class/Type level resource annotation

 
aze opuiy
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
aze opuiy
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic