You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Delamere <ho...@michael-delamere.de> on 2002/07/27 16:10:44 UTC

Tomcat + JNDI

Hi,

I´m trying to access a bean via JNDI using Tomcat.  Unfortunately, reading
documentation and mailing-lists hasn´t helped me very much.  Could someone
please expalin to me what is involved in accessing a bean in tomcat via
JNDI.  Here´s what I´ve done so far:

========== WEB.XML ====================
<resource-env-ref>
  <description>
    Object factory for MyBean instances.
  </description>
  <resource-env-ref-name>
    jdo/FindMe
  </resource-env-ref-name>
  <resource-env-ref-type>
    com.test.osforum.services.FindMe
  </resource-env-ref-type>
</resource-env-ref>

======== MY ACTION SERVLET ============
  Context context;
  Context envCtx;
  try {
   context = new InitialContext();
   envCtx = (Context) context.lookup("java:comp/env");

    FindMe findme = (FindMe) envCtx.lookup("jdo/FindMe");
   message = findme.getSillyMessage();
   request.setAttribute("message", message);
  } catch (NamingException e) {
   System.out.println("-----| CATCH NAMING EXCEPTION-: " + e.toString() + "
|----- \n\n");
   e.printStackTrace();
  }
========================================

The above results in a " javax.naming.NamingException: Cannot create
resource instance".  Could someone please point me in the right direction.

Regards,

Michael



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat + JNDI

Posted by Michael Delamere <ho...@michael-delamere.de>.
thanks Craig,

that´s what I thought I read....  I was hoping that maybe there is an easier
way then wrinting my own factory to retreive objects via JNDI.  What I need
is a factory which can return any JDO objects.  I noticed in the particular
example provided by tomcat that you have to initialize the object in the
factory.  So that would mean that every time I create a new JDO object, I
have to add it to the factory.  Or have I missed something here?  Any
suggestions?

Thanks very much,

Michael



----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Saturday, July 27, 2002 6:09 PM
Subject: Re: Tomcat + JNDI


> Have you defined the resource itself in server.xml?  You'll need to set up
> the appropriate <Resource> and <ResourceParams> elements there in order to
> define how Tomcat is actually supposed to create the object factory for
> this resource.  See the jndi-resources-howto.html for more information on
> creating object factories for your own beans.
>
> Craig
>
>
> On Sat, 27 Jul 2002, Michael Delamere wrote:
>
> > Date: Sat, 27 Jul 2002 16:10:44 +0200
> > From: Michael Delamere <ho...@michael-delamere.de>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > To: tomcat-user@jakarta.apache.org
> > Subject: Tomcat + JNDI
> >
> > Hi,
> >
> > I´m trying to access a bean via JNDI using Tomcat.  Unfortunately,
reading
> > documentation and mailing-lists hasn´t helped me very much.  Could
someone
> > please expalin to me what is involved in accessing a bean in tomcat via
> > JNDI.  Here´s what I´ve done so far:
> >
> > ========== WEB.XML ====================
> > <resource-env-ref>
> >   <description>
> >     Object factory for MyBean instances.
> >   </description>
> >   <resource-env-ref-name>
> >     jdo/FindMe
> >   </resource-env-ref-name>
> >   <resource-env-ref-type>
> >     com.test.osforum.services.FindMe
> >   </resource-env-ref-type>
> > </resource-env-ref>
> >
> > ======== MY ACTION SERVLET ============
> >   Context context;
> >   Context envCtx;
> >   try {
> >    context = new InitialContext();
> >    envCtx = (Context) context.lookup("java:comp/env");
> >
> >     FindMe findme = (FindMe) envCtx.lookup("jdo/FindMe");
> >    message = findme.getSillyMessage();
> >    request.setAttribute("message", message);
> >   } catch (NamingException e) {
> >    System.out.println("-----| CATCH NAMING EXCEPTION-: " + e.toString()
+ "
> > |----- \n\n");
> >    e.printStackTrace();
> >   }
> > ========================================
> >
> > The above results in a " javax.naming.NamingException: Cannot create
> > resource instance".  Could someone please point me in the right
direction.
> >
> > Regards,
> >
> > Michael
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tomcat + JNDI

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Have you defined the resource itself in server.xml?  You'll need to set up
the appropriate <Resource> and <ResourceParams> elements there in order to
define how Tomcat is actually supposed to create the object factory for
this resource.  See the jndi-resources-howto.html for more information on
creating object factories for your own beans.

Craig


On Sat, 27 Jul 2002, Michael Delamere wrote:

> Date: Sat, 27 Jul 2002 16:10:44 +0200
> From: Michael Delamere <ho...@michael-delamere.de>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Tomcat + JNDI
>
> Hi,
>
> I´m trying to access a bean via JNDI using Tomcat.  Unfortunately, reading
> documentation and mailing-lists hasn´t helped me very much.  Could someone
> please expalin to me what is involved in accessing a bean in tomcat via
> JNDI.  Here´s what I´ve done so far:
>
> ========== WEB.XML ====================
> <resource-env-ref>
>   <description>
>     Object factory for MyBean instances.
>   </description>
>   <resource-env-ref-name>
>     jdo/FindMe
>   </resource-env-ref-name>
>   <resource-env-ref-type>
>     com.test.osforum.services.FindMe
>   </resource-env-ref-type>
> </resource-env-ref>
>
> ======== MY ACTION SERVLET ============
>   Context context;
>   Context envCtx;
>   try {
>    context = new InitialContext();
>    envCtx = (Context) context.lookup("java:comp/env");
>
>     FindMe findme = (FindMe) envCtx.lookup("jdo/FindMe");
>    message = findme.getSillyMessage();
>    request.setAttribute("message", message);
>   } catch (NamingException e) {
>    System.out.println("-----| CATCH NAMING EXCEPTION-: " + e.toString() + "
> |----- \n\n");
>    e.printStackTrace();
>   }
> ========================================
>
> The above results in a " javax.naming.NamingException: Cannot create
> resource instance".  Could someone please point me in the right direction.
>
> Regards,
>
> Michael
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>