You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Elisabeth Julg <el...@steria.com> on 2002/03/21 16:06:00 UTC

JNDI - Custom Factory

Hi,

  I have a problem with NamingException : "Cannot create resource instance"
with code :

    initCtx = new InitialContext(); }
    envCtx = (Context) initCtx.lookup("java:comp/env");
    System.out.println(envCtx.lookup("bean/MemoireFactory"));
     ||
     ====> NamingException : "Cannot create resource instance"

Have you an idea to correct this ?



Configuration :
---------------
 web.xml :
  <resource-env-ref>
    <resource-env-ref-name>bean/MemoireFactory</resource-env-ref-name>
    <resource-env-ref-type>pastel.jsp.HD_Exemple</resource-env-ref-type>
  </resource-env-ref>

 server.xml :
  <context ....>
    <Resource name="bean/MemoireFactory" auth="Container"
type="pastel.jsp.HD_Exemple"/>
    <ResourceParams name="bean/MemoireFactory">
      <parameter>
        <name>factory</name>
        <value>pastel.jsp.MemoireFactory></value>
      </parameter>
      </ResourceParams>
    </Context>

MemoireFactory :

public class MemoireFactory implements ObjectFactory
{
  public MemoireFactory() {System.out.println("
MemoireFactory.constructeur");}
  public Object getObjectInstance(Object obj,Name name, Context nameCtx,
Hashtable environment)
    throws NamingException
  {
    // Acquire an instance of our specified bean class
    HD_Exemple bean = new HD_Exemple();

    // Customize the bean properties from our attributes
    Reference ref = (Reference) obj;
    Enumeration addrs = ref.getAll();
    while (addrs.hasMoreElements())
    {
      RefAddr addr = (RefAddr) addrs.nextElement();
      String nom = addr.getType();
      String value = (String) addr.getContent();
      System.out.println("MemoireFactory "+nom+"="+value);
    }

    // Return the customized instance
    return (bean);
  }
}

I have read the Tomcat's HowTo about JNDI Resources.
The version of Tomcat is : 4.0.2.

Thanks for your help,

Elisabeth
Toulouse - France


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>