• 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

<resource-ref> element in JNDI Configuration

 
Greenhorn
Posts: 26
IntelliJ IDE jQuery Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I am reading Spring in Action third edition. I am on chapter 6 data access with Spring. I have a question while configuring a datasource
we can use the option JNDI Datasource. In the spring configuration file, we give something like

It says that <resource-ref> true prepends java:comp/env/. My question is what does resource-ref mean and why do we use it?
Thankyou

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have already answered your own question of 'what it does'.

The reason this is needed is because the JEE spec does not standardize JNDI naming conventions hence different application servers follow different rules. Some like Tomcat bind to the JNDI tree with the java:/comp/env/ prefix so in this case you would set this flag to true. It is really application server specific. If you are only going to support one application server it is just a matter of figuring out which one is right and defining it correctly.

 
Peter Piddle
Greenhorn
Posts: 26
IntelliJ IDE jQuery Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Bill,
Amazing. Thankyou very much. So it means that we set it to true or not, it's just a matter of choice as such kind of namespace
convention will be separate for every server. Am i intercepting correct?
Thankyou,
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is recommended but not required by J2EE to use this convention. So it is possible that it will be bound differently by the application server in which case resource-ref="true" would not find your JDNI in that context. However in my experience usually setting this to true is the safest bet.

From the API docs

JNDI names may or may not include the "java:comp/env/" prefix expected by J2EE applications when accessing a locally mapped (ENC - Environmental Naming Context) resource. If it doesn't, the "java:comp/env/" prefix will be prepended if the "resourceRef" property is true (the default is false) and no other scheme (e.g. "java:") is given.







 
Peter Piddle
Greenhorn
Posts: 26
IntelliJ IDE jQuery Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Bill,
Thanks a ton. I understood.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic