• 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

mappedName and name attributes

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The @Resource annotation has two attributes as name and mappedName. I've seen some books uses "name" attribute, and some books uses "mappedName" attribute, especially for JMS client examples. Please look at the following two examples:






I'm really confused with above two attributes. Are they same?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone answer this question?
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mappedName are dependent on app server if may map this local name to JNDI name. you can say mapped name as global JNDI.
name is a name of the resource which will be injected.

http://java.sun.com/javaee/5/docs/api/javax/annotation/Resource.html#mappedName()
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try already to submit this post but it seams that this system want something else.
So, the @Resource is heavy overloaded and this make it a little bit fuzzy. I identify 3 main ways to use it :
1.the container resource which is not attached in the container context - like ServeltContext or the TimeService. For this you don't need the name parameter.


2.inject a resource and bound it to a certain ENC name (if this resource is not already bounded). In this way other classes (and beans) can reach this resource via jndi lookup using the given ENC name.



2.1.the vendor specific name mapping. There are cases when a vendor map some resource under some vendor specific name. If you use this resources then the you get a dependency on a specific container. So you need to map this vendor specific to a ENC name.


Here you map the vendor specific "vendor" name to a container independent ENC name ("myDS")

3.The class level - used to defines which resources will be located via JNDI in a specific class.


the logic is similar with the one on the 2 and 2.1
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Nitin and Mihai,

Mihai, do we need to understand about the "name" element (since it is vendor specific) for the exam?
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name and the mappedName are both @Resource parameters, you need to understand how this is working for the exam.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again Mihai.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic