简体   繁体   中英

Vertx JDBC NoSuchMethodError 'java.sql.Connection io.agroal.api.transaction.TransactionIntegration.getConnection()'

I'm trying to use vertx JDBC with MS SQL Server.

I get the following stacktrace:

Exception in thread "vertx-jdbc-service-get-connection-thread" Exception in thread "vertx-jdbc-service-get-connection-thread" java.lang.NoSuchMethodError: 'java.sql.Connection io.agroal.api.transaction.TransactionIntegration.getConnection()'
    at io.agroal.pool.ConnectionPool.wrapperFromTransaction(ConnectionPool.java:162)
    at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:129)
    at io.agroal.pool.DataSource.getConnection(DataSource.java:61)
    at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$null$4(JDBCClientImpl.java:232)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:831)
java.lang.NoSuchMethodError: 'java.sql.Connection io.agroal.api.transaction.TransactionIntegration.getConnection()'
    at io.agroal.pool.ConnectionPool.wrapperFromTransaction(ConnectionPool.java:162)
    at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:129)
    at io.agroal.pool.DataSource.getConnection(DataSource.java:61)
    at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$null$4(JDBCClientImpl.java:232)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:831)

part of my build.gradle :

  implementation platform("io.vertx:vertx-stack-depchain:4.2.1")
  implementation "io.vertx:vertx-core"
  implementation 'io.vertx:vertx-jdbc-client:4.2.1'
  implementation "io.vertx:vertx-lang-groovy"
  implementation 'io.agroal:agroal-api:1.13'
  implementation 'io.agroal:agroal-pool:1.13'
  implementation "com.microsoft.sqlserver:mssql-jdbc:9.4.0.jre16"

I tried choosing other versions, but I always get the same error. I tried looking for the library function, but I can't find any version of TransactionIntegration with a getConnection() method.

My code:

import io.vertx.core.AbstractVerticle;
import io.vertx.core.*;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;

public class MainVerticle extends AbstractVerticle {

     @Override
     public void start(Promise<Void> startPromise) throws Exception {

        JDBCPool pool = JDBCPool.pool(
                vertx,
                new JDBCConnectOptions()
                .setJdbcUrl("jdbc:sqlserver://some_ip;databaseName=mydatabase")
                .setUser("user")
                .setPassword("password"),
                new PoolOptions().setMaxSize(16)
                );
        pool
          .query("SELECT * FROM test")
          .execute()
          .onFailure(e -> {
              e.printStackTrace();
          })
    }
}

The current 4.2.1 release seems to rely on agroal 1.12.

Given that you're getting a NoSuchMethodError I would assume it can be related to the fact that the compiled jar was against 1.12, but you're running against 1.13 and some agroal classes changed in between?

Try to downgrade to 1.12, and it should solve your error.

Apparently, gradle is just bugged.

I changed agroal version to 1.12, as suggested by Paulo Lopes. However, this did not solve the problem.

I don't know, what exactly solved it, but I'll just list exactly what I did:

  • removing both agroal dependencies
  • inserting agroal-api
  • removing agroal-api
  • inserting agroal-api
  • inserting agroal-pool

I did not check, whether or not it was necessary to use agroal 1.12, or what step exactly solved it. And I don't intend to try it, I'm just happy, it finally works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM