wood burning stoves*
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
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to JNDI-Cannot create resource instance" Watch "How to JNDI-Cannot create resource instance" New topic
Author

How to JNDI-Cannot create resource instance

Krishan Chauhan
Ranch Hand

Joined: Mar 12, 2008
Posts: 32
Hi

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
org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:114)
....
....

In my web.xml i have made the entry as
<resource-env-ref>
<description>
Object factory for MyBean instances
</description>
<resource-env-ref-name>
bean/MyBeanFactory
</resource-env-ref-name>
<resource-env-ref-type>
com.MyBean
</resource-env-ref-type>
</resource-env-ref>

Also in server.xml, i have specified

<Resource name="bean/MyBeanFactory" auth="Container"
type="com.MyBean"
factory="org.apache.naming.factory.BeanFactory"
bar="23"/>

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");
System.out.println(envCtx);
bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
} catch (NamingException e) {
e.printStackTrace();
}

This is when i get the exception.

Could any one help me out?

Thanks
[ 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
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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: http://aspose.com/file-tools
 
subject: How to JNDI-Cannot create resource instance
 
Similar Threads
deployment exception
jndi PROBLEM
but to intialize bean class in web.xml
Configuring JNDI for JavaBean in Tomcat 5
JNDI lookup