Rob,
Thanks for that info. It looks correct to me. You have defined the
correct factory for Tomcat's own JDBC pool are you are correctly casting
to an instance of a DataSource from that pool.
That caused me to go back and take a closer look at your original report.
It appears from the class loaders that you have placed the JAR for
Tomcat's JDBC pool (tomcat-jdbc.jar) in WEB-INF/lib. That won't work -
hence why you actually get the default Commons DBCP2 based pool. You
need to place tomcat-jdbc.jar in $CATALINA_BASE/lib.
Mark
On 16/03/2021 02:34, Rob Sargent wrote:
A little late in responding to Mark's questions. Been on a short
walk-about.
On 3/11/21 12:17 PM, Mark Thomas wrote:
On 11/03/2021 19:08, Rob Sargent wrote:
I've started getting this error, though I've been running fine since
days of "localhost" issue help.
class org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
class org.apache.tomcat.jdbc.pool.DataSource
(org.apache.tomcat.dbcp.dbcp2.BasicDataSource is in unnamed module
of loader 'app'; org.apache.tomcat.jdbc.pool.DataSource is in
unnamed module of loader
org.apache.catalina.loader.ParallelWebappClassLoader @33c9efd6)
I'm most confused by the "'app'" loader. Who's is that? I doesn't
look like a TC thing. I have a package called "app" which includes
the main() of my embedded server.
Apologies as I'm not fully up on the modules notion and was
blissfully getting by without dealing with that. Until now. You can
find me over in the Java Organization section of hell.
Which database connection pool do you want to use?
Tomcat's package renamed copy of Apache Commons DBCP
or
Tomcat's own JDBC Pool?
(there isn't much to choose between them these days).
How is the DataSource defined?
My context.xml is as follows
<Context reloadable="true">
<Resource
name="jdbc/sgsdb/version4019"
url="jdbc:postgresql://gitanmax:5432/version4019"
driverClassName="org.postgresql.Driver"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="false"
testOnBorrow="true"
testOnReturn="false"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
maxActive="50"
initialSize="3"
maxWait="10000"
removeAbandonedTimeout="60"
minEvictableIdleTimeMillis="30000"
minIdle="1"
maxIdle="5"
logAbandoned="true"
removeAbandoned="true"
username=""
password=""
/>
<Valve
className="org.apache.catalina.valves.AccessLogValve"
prefix="sgs_access">
</Valve>
</Context>
Do you know what code is triggering the failing cast?
public DataSource getDataSource(String dbname) {
DataSource lookupDS = null;
try {
InitialContext ic = new InitialContext();
Context sgsContext = (Context) ic.lookup("java:/comp/env");
//*** this next line is the cast which blows up.
lookupDS = (org.apache.tomcat.jdbc.pool.DataSource)
sgsContext.lookup("jdbc/sgsdb/"+dbname);
}
catch (javax.naming.NamingException ne) {
lookupDS = null;
log(ne.getMessage()); //TODO
}
return lookupDS;
}
The app loader is one of the class loaders in the standard Java class
loader hierarchy. I forget the exact details. Google should be able to
tell you that.
Got it.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org