You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Adam Rauch <ad...@labkey.com> on 2018/04/17 16:25:25 UTC

ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory starting in 7.0.86

Our code retrieves DataSources using JNDI, with code similar to this:

     new InitialContext().lookup("java:comp/env/jdbc/labkeyDataSource");

With a simple DataSource definition that doesn't specify a "factory" 
attribute, this code now throws in Tomcat 7.0.86. (It works in 7.0.85, 
8.0.50, 8.5.30, and 9.0.7.)

According to the tomcat70 GitHub mirror, a recent change to 
Constants.java switched DBCP_DATASOURCE_FACTORY to 
"org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory", which seems 
suspicious. See 
https://github.com/apache/tomcat70/commit/08b7ca0fae77063202d82e719eb35e4eda881bbf

Root cause stack trace is:

Caused by: java.lang.ClassNotFoundException: 
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at 
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:115)
        ... 26 more

Thanks,
Adam

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


Re: ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory starting in 7.0.86

Posted by Mark Thomas <ma...@apache.org>.
On 17/04/18 17:25, Adam Rauch wrote:
> Our code retrieves DataSources using JNDI, with code similar to this:
> 
>     new InitialContext().lookup("java:comp/env/jdbc/labkeyDataSource");
> 
> With a simple DataSource definition that doesn't specify a "factory"
> attribute, this code now throws in Tomcat 7.0.86. (It works in 7.0.85,
> 8.0.50, 8.5.30, and 9.0.7.)
> 
> According to the tomcat70 GitHub mirror, a recent change to
> Constants.java switched DBCP_DATASOURCE_FACTORY to
> "org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory", which seems
> suspicious. See
> https://github.com/apache/tomcat70/commit/08b7ca0fae77063202d82e719eb35e4eda881bbf

Yep. That is an error on my part. Explicitly setting the factory is the
work-around.

I'll get that fixed shortly.

Mark


> 
> 
> Root cause stack trace is:
> 
> Caused by: java.lang.ClassNotFoundException:
> org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>        at java.lang.Class.forName0(Native Method)
>        at java.lang.Class.forName(Class.java:264)
>        at
> org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:115)
> 
>        ... 26 more
> 
> Thanks,
> Adam
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory starting in 7.0.86

Posted by Konstantin Kolinko <kn...@gmail.com>.
2018-04-17 22:18 GMT+03:00 Shawn Heisey <ap...@elyograg.org>:
> ...
>
> You should be able to work around the problem by defining a factory in
> your pools set to "org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
> so that the default is not used.  This addition should only be made on
> configs for Tomcat 7.
>

There exists a system property that specifies the factory used for data sources.
Thus it is easy to workaround this by adding a line to
catalina.properties (or a -D value to CATALINA_OPTS in setenv.sh file)

I created a bugzilla entry, to better document the issue and the workaround:
https://bz.apache.org/bugzilla/show_bug.cgi?id=62316

Best regards,
Konstantin Kolinko

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


Re: ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory starting in 7.0.86

Posted by Shawn Heisey <ap...@elyograg.org>.
On 4/17/2018 10:25 AM, Adam Rauch wrote:
> According to the tomcat70 GitHub mirror, a recent change to
> Constants.java switched DBCP_DATASOURCE_FACTORY to
> "org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory", which seems
> suspicious. See
> https://github.com/apache/tomcat70/commit/08b7ca0fae77063202d82e719eb35e4eda881bbf

I've recently been asking the list about pool configurations in Tomcat
7, and I've gotten an education about it as a result.

The info I've received says that Tomcat 7 uses dbcp 1.4.  Version 8
updated to dbcp2.

To me, that looks like an incorrect change for version 7.  I think the
line in the change with the default class name for the factory should be
reverted.

You should be able to work around the problem by defining a factory in
your pools set to "org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
so that the default is not used.  This addition should only be made on
configs for Tomcat 7.

That commit says it was prep work for BZ bug number 50019.  I have put a
note on that bug about this.

https://bz.apache.org/bugzilla/show_bug.cgi?id=50019

Thanks,
Shawn


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