tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adib <amsl...@gmail.com>
Subject Re: Bug with tomcat JDBC connection pool?
Date Mon, 05 Mar 2012 04:59:07 GMT
Tomcat source for class org.apache.naming.factory.ResourceFactory line
112 contains the following block of code which defaults the data
source to the DBCP unless the system property
javax.sql.DataSourceFactory is set.

However when I set javax.sql.DataSource factory to point to the Tomcat
jdbc connection factory I end up with different exceptions.

One thing I that does not make sense to me is why tomcat would be
trying to create a datasource object when a resource-ref is
encountered.

if (ref.getClassName().equals("javax.sql.DataSource")) {
                    String javaxSqlDataSourceFactoryClassName =
                        System.getProperty("javax.sql.DataSource.Factory",
                                           Constants.DBCP_DATASOURCE_FACTORY);
                    try {
                        factory = (ObjectFactory)
                            Class.forName(javaxSqlDataSourceFactoryClassName)
                            .newInstance();
                    } catch (Exception e) {
                        NamingException ex = new NamingException
                            ("Could not create resource factory instance");
                        ex.initCause(e);
                        throw ex;
                    }
                }


On Sun, Mar 4, 2012 at 3:37 PM, Adib <amslist@gmail.com> wrote:
> Hi,
>
> I think I have run into a bug with tomcat, but wanted to check with
> the user list to make sure it is a bug before  I file it.
>
> Background:
>
> I am using the tomact jdbc pool over the dbcp pool and I am embedding
> tomcat as part of an application that clients install on their data
> centers.
>
> 1) delete the lib\tomcat-dbcp.jar from the tomcat\lib
>
> 2) Configure a jdbc connection pool in server.xml in the GlobalNamingResource
>
> <GlobalNamingResources>
>    <Resource
>                factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
>                auth="Container"
>                type="javax.sql.DataSource"
>                jdbcInterceptors="StatementFinalizer;ResetAbandonedTimer"
>
>               name="jdbc/testDB"
>               driverClassName="org.postgresql.Driver"
>               url="jdbc:postgresql://127.0.0.1:5432/tes"
>               username="test"
>               password="test"
>
>               maxActive="20"
>               maxIdle="10"
>              maxWait="-1"
>        />
>  </GlobalNamingResources>
>
> 3) Add a resource ref to the web.xml
>
>  <resource-ref>
>    <description>Test Datasource</description>
>    <res-ref-name>jdbc/testDB</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
>    <res-auth>Container</res-auth>
>  </resource-ref>
>
> 4) do an a lookup for the data source
>
> try {
>                        InitialContext ctx = new InitialContext();
>                        Object object = ctx.lookup("java:/comp/env/jdbc/testDB");
>                        System.out.println(object.getClass().getCanonicalName());
>                } catch (NamingException e) {
>                        e.printStackTrace();
>                }
>
> 5)  Tomcat throws an exception  java.lang.ClassNotFoundException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory full stack trace
> below.
>
> It is not clear why it would be looking for dbcp DataSource when i
> have my data source defined   using
> factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
>
> Interestingly if the resource is defined in context.xml in META-INF
> for the war there are no exceptions it just works.
>
> Any thoughts on whether this is a bug or not?
>
> Cheers,
>
> ----
>
> NFO: Starting Servlet Engine: Apache Tomcat/7.0.26
> Mar 4, 2012 10:09:29 AM org.apache.catalina.core.NamingContextListener
> addResource
> WARNING: Failed to register in JMX: javax.naming.NamingException:
> Could not create resource factory instance [Root exception is
> java.lang.ClassNotFoundException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
> Mar 4, 2012 10:09:29 AM org.apache.coyote.AbstractProtocol start
> INFO: Starting ProtocolHandler ["http-bio-8080"]
> Mar 4, 2012 10:09:29 AM org.apache.catalina.startup.Catalina start
> INFO: Server startup in 852 ms
> javax.naming.NamingException: Could not create resource factory
> instance [Root exception is java.lang.ClassNotFoundException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
>        at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:121)
>        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
>        at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
>        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
>        at javax.naming.InitialContext.lookup(InitialContext.java:392)
>        at com.example.HelloServlet.doGet(HelloServlet.java:34)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
>        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
>        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
>        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
>        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
>        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
>        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
>        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
>        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
>        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:680)
> Caused by: java.lang.ClassNotFoundException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>        at java.lang.Class.forName0(Native Method)
>        at java.lang.Class.forName(Class.java:169)
>        at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:117)
>        ... 30 more

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


Mime
View raw message