tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Rowe <ichabo...@gmail.com>
Subject jndi question
Date Mon, 22 Aug 2005 06:26:49 GMT
I have tried for several hours now to get connection pooling for my 
MySql database to work, but have been unable to do so.  I keep getting 
this error:

javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.commons.dbcp.BasicDataSourceFactory


I checked to make sure this class was in my classpath:

 [shell]# javap org.apache.commons.dbcp.BasicDataSourceFactory
Compiled from "BasicDataSourceFactory.java"
public class org.apache.commons.dbcp.BasicDataSourceFactory extends 
java.lang.Object implements javax.naming.spi.ObjectFactory{
    public org.apache.commons.dbcp.BasicDataSourceFactory();
    public java.lang.Object getObjectInstance(java.lang.Object, 
javax.naming.Name, javax.naming.Context,  java.util.Hashtable) throws 
java.lang.Exception;
    public static javax.sql.DataSource 
createDataSource(java.util.Properties)       throws java.lang.Exception;
    static {};
}

I set up my jndi datasource using the admin module.  Here's how it wrote 
out my server.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  <Listener 
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener 
className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      pathname="conf/tomcat-users.xml"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
      name="jdbc/appname"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      password="xxxx"
      maxIdle="30"
      maxWait="10"
      validationQuery="SELECT 1"
      username="username"
      url="jdbc:mysql://localhost:3306/appname"
      maxActive="100"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="8080"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxThreads="150"
        maxSpareThreads="75"
        maxHttpHeaderSize="8192">
    </Connector>
    <Connector
        port="8443"
        scheme="https"
        secure="true"
        minSpareThreads="25"
        clientAuth="false"
        maxThreads="150"
        maxSpareThreads="75"
        maxHttpHeaderSize="8192">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost"
          unpackWARs="true" autoDeploy="true"
          xmlValidation="false" xmlNamespaceAware="false">
        <Context
            path="/devtrans">
          <Resource
            auth="Container"
            description="DB Connection"
            name="jdbc/appname"
            type="javax.sql.DataSource"/>
          
<WatchedResource>/usr/local/tomcat/server/conf/context.xml</WatchedResource>
          <WatchedResource>WEB-INF/web.xml</WatchedResource>
        </Context>
      </Host>
    </Engine>
  </Service>
</Server>

Here's what's in my web.xml file:
<resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/appname</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

It's bombing out on this code:

    Properties p=new Properties();
     
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.commons.dbcp.BasicDataSourceFactory");
     p.put(Context.PROVIDER_URL,"jdbc:mysql://localhost:3306");
     Context initCtx = new InitialContext(p); // here's where it dies

Can someone please help me, or at least point me in the direction of 
some documentation that I've missed?  I've searched google and every 
other search engine I can think of.  Thanks in advance.

Sean Rowe




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message