Maven service factory not resolving jdbc driver

215 views
Skip to first unread message

David Bush

unread,
Aug 18, 2018, 4:23:20 PM8/18/18
to vert.x
I'm trying to create some services using the Maven Service Factory. The services that don't use JDBC are working fine. The ones that need the mysql driver aren't finding it at run time. I get class not found. I thought it might be something with c3po so I tried Hikari instead. In that case HikariConfig class is not found even though I include it in my pom as not optional.

I know I can include the driver on the class path, but that kind of defeats the purpose of the maven service factory. 

Has anyone else gotten this to work?


Here's the driver dependency I'm using:


<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

Julien Viet

unread,
Aug 18, 2018, 5:33:09 PM8/18/18
to ve...@googlegroups.com
can you show the printed CNFE ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/2638c885-8505-41e8-a31e-3731765cf5c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Bush

unread,
Aug 18, 2018, 8:25:06 PM8/18/18
to vert.x
Here is the result:

BTW, the same code works with a fat jar. 

Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@6c62fd0d is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 
application_1  | Could not load driverClass com.mysql.cj.jdbc.Driver 
application_1  | java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
application_1  | at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
application_1  | at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
application_1  | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
application_1  | at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
application_1  | at java.lang.Class.forName0(Native Method)
application_1  | at java.lang.Class.forName(Class.java:264)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:143)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:173)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
application_1  | at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
application_1  | 
application_1  | com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@40d00cb0 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:  
application_1  | java.sql.SQLException: No suitable driver
application_1  | at java.sql.DriverManager.getDriver(DriverManager.java:315)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
application_1  | at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
application_1  | 
application_1  | Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@6c62fd0d is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 
application_1  | Unable to authenticate 
application_1  | java.sql.SQLException: Connections could not be acquired from the underlying database!
application_1  | at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
application_1  | at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
application_1  | at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$getConnection$3(JDBCClientImpl.java:197)
application_1  | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
application_1  | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
application_1  | at java.lang.Thread.run(Thread.java:748)
application_1  | Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
application_1  | ... 5 more
application_1  | Caused by: java.sql.SQLException: No suitable driver
application_1  | at java.sql.DriverManager.getDriver(DriverManager.java:315)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
application_1  | at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
application_1  | at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
application_1  | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
application_1  | at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
application_1  | at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

Julien Viet

unread,
Aug 20, 2018, 3:56:38 AM8/20/18
to ve...@googlegroups.com
Hi,

I think you are running into a corner case because the io.vertx.* classes are never loaded from the isolating classloader

instead you should try to load the DataSource in your code and pass it to vertx-jdbc-client

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

David Bush

unread,
Aug 21, 2018, 10:54:35 AM8/21/18
to vert.x
Thanks Julien. That worked. For those seeing this in the wonderful future, I did this in my verticle loaded as a maven service to create the reactivex JDBCClient:

JsonObject authMysqlConfig = config().getJsonObject("auth_mysql");
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl(authMysqlConfig.getString("url"));
dataSource.setUser(authMysqlConfig.getString("user"));
dataSource.setPassword(authMysqlConfig.getString("password"));

JDBCClient jdbcClient = new JDBCClient(io.vertx.ext.jdbc.JDBCClient.create(vertx.getDelegate(), dataSource));
JDBCAuth authProvider = JDBCAuth.create(vertx, jdbcClient);
Reply all
Reply to author
Forward
0 new messages