File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How to JNDI-Cannot create resource instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to JNDI-Cannot create resource instance" Watch "How to JNDI-Cannot create resource instance" New topic

How to JNDI-Cannot create resource instance

Krishan Chauhan
Ranch Hand

Joined: Mar 12, 2008
Posts: 32

I am using Tomcat 5.5. I am trying to access the environmental entries that i have specified in web.xml through JNDI.

I have followed the same steps given in documentation of Tomcat but i am getting javax.naming.NamingException: Cannot create resource instance

In my web.xml i have made the entry as
Object factory for MyBean instances

Also in server.xml, i have specified

<Resource name="bean/MyBeanFactory" auth="Container"

Then I am trying to do the lookup

Context initCtx;
MyBean bean = new MyBean();
try {
initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
} catch (NamingException e) {

This is when i get the exception.

Could any one help me out?

[ September 29, 2008: Message edited by: Krishan Chauhan ]
Krishan Chauhan
Ranch Hand

Joined: Mar 12, 2008
Posts: 32
can anyone help me out ?
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

Hi there,

Just rushing past this topic so quick note:

Does Tomcat allow you to look at the JNDI tree? IIRC Tomcat ships with a JndiServlet that can be used to list the content of a local JNDI tree. It is found in the "examples" Webapp. Run that and see if your bean is actually in the JNDI tree where you think it is...

Hope the helps?

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
I agree. Here's the link:
subject: How to JNDI-Cannot create resource instance
It's not a secret anymore!