Bug 62316

Summary: JDBC resources fail, ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory
Product: Tomcat 7 Reporter: Konstantin Kolinko <knst.kolinko>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: regression    
Priority: P2    
Version: 7.0.86   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Konstantin Kolinko 2018-04-20 05:59:31 UTC
(Filing a Bugzilla entry to better document the issue and document a workaround.)

Mailing list thread (2018-04-17):
"ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory starting in 7.0.86"
https://tomcat.markmail.org/thread/gg566guvffchbcez

This is a regression in Tomcat 7.0.86. This was fixed in revision r1829376.


Steps to reproduce:

1. Configure a <Resource> entry with a database connection, without specifying a factory attribute. See examples here:
http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

2. If the <Resource> is configured in <GlobalNamingResources> element in server.xml, the following errors are visible in catalina.#date.log when Tomcat starts up:

20-Apr-2018 03:11:24.196 WARNING [main] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]
20-Apr-2018 03:11:24.212 WARNING [main] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]
20-Apr-2018 03:11:24.290 SEVERE [main] org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans Exception processing Global JNDI Resources
 javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]
	at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:119)
	at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:848)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
	at org.apache.naming.NamingContextBindingsEnumeration.nextElementInternal(NamingContextBindingsEnumeration.java:117)
	at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:71)
	at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:34)
	at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:138)
	at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:145)
	at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:110)
	at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEvent(GlobalResourcesLifecycleListener.java:82)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:388)
	at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:333)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:751)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:705)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:115)
	... 23 more
Comment 1 Konstantin Kolinko 2018-04-20 06:04:19 UTC
WORKAROUND: Add the following line to conf/catalina.properties file

javax.sql.DataSource.Factory=org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory


This system property is documented in
http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html#Other