• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is resource-ref for?  RSS feed

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am using tomcat 6.0.18. In the server.xml file there is a definiction of a GlobalNamingResource for the UserDatabase. In my application I have a /META-INF/context.xml file with an "resource-link" element that point to that user database:

Then, in one of my servlets in have the code:

and this works fine.

I read that if you want to use any resource for the environment, you need to declare it in web.xml with: resource-ref or resource-env-ref. My example works fine without any of these, so what's the point of using them? And what is the difference between the two?
Also, in Glassgish, I am able to look up EJBs without using ejb-ref elements in my web.xml - so what are they for?
Cheers.
[ November 07, 2008: Message edited by: Raf Szczypiorski ]
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read that if you want to use any resource for the environment, you need to declare it in web.xml with: resource-ref or resource-env-ref.

Not necessarily.A link to a global JNDI resource can be specified in the context.xml as well.

Also, in Glassgish, I am able to look up EJBs without using ejb-ref elements in my web.xml - so what are they for?

EJB references can either be directly injected in the code using annotations or specified in xml.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB references can either be directly injected in the code using annotations or specified in xml.


What xml are you talking about? ejb-jar.xml or web.xml? I am able to do a JNDI lookup without any entry in web.xml and ejb-jar.xml, the EJB is defined with annotations.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What xml are you talking about? ejb-jar.xml or web.xml? I am able to do a JNDI lookup without any entry in web.xml and ejb-jar.xml, the EJB is defined with annotations


If the EJB is injected using an annotation like @EJB <EJBname type;> then you require entry in neither ejb-jar.xml nor web.xml. The container would take care of adding a JNDI entry for the injected enterprise bean.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!