Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to JNDI-Cannot create resource instance

 
Krishan Chauhan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone help me out ?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic