5

Tomcat7: 7.0.30-0ubuntu1.1

Tomcat 7 has the jar files commons-dbcp.jar and tomcat-dbcp.jar but in tomcat-dbcp.jar, it is the file org.apache.tomcat.dbcp.BasicDataSourceFactory class instead of org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory that is looking for.

root cause

javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
    org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:121)
    javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:722)
7

A solution is given for this same problem on StackOverflow by modifying the resource tag in conf/context.xml to use factory="org.apache.commons.dbcp.BasicDataSourceFactory" instead of Tomcat 7 default factory. You can see there the cause of this problem.

The resource tag will look something like (taken from the referenced answer):

<Resource name="jdbc/myDataSource"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/myDatabase"
    username="username" password="password"
    validationQuery="SELECT COUNT(*) FROM MY_TABLE"
    factory="org.apache.commons.dbcp.BasicDataSourceFactory" />
3

The default DataSource factory in tomcat 7 is org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory. This is contained in a jar file which the Debian maintainers don't distribute.

Tomcat 7 now includes another connection pool implementation which can be used instead, but it isn't default.

org.apache.tomcat.jdbc.pool.DataSourceFactory

We could change the default factory to this that it is already included in the current distribution and so solve this problem.

Ubuntu version: 12.10

tomcat7: 7.0.30-0ubuntu1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.