tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elisabeth Julg" <elisabeth.j...@steria.com>
Subject JNDI - Custom Factory
Date Thu, 21 Mar 2002 15:06:00 GMT
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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message