• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class/Type level resource annotation

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic