0

我正在尝试将 vertx JDBC 与 MS SQL Server 一起使用。

我得到以下堆栈跟踪:

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)

我的一部分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"

我尝试选择其他版本,但总是遇到同样的错误。我试图寻找库函数,但我找不到任何版本的方法。TransactionIntegrationgetConnection()

我的代码:

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();
          })
    }
}
4

2 回答 2

0

当前的 4.2.1 版本似乎依赖于 agroal 1.12。

鉴于你得到一个NoSuchMethodError我会假设它可能与编译的 jar 是针对 1.12 的事实有关,但是你正在针对旧版本运行,可能是 1.0 或 1.1。查看 github,您可以找到与这些版本匹配的跟踪。

尝试升级到 1.12,它应该可以解决您的错误。

于 2021-11-17T10:12:41.630 回答
0

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.

于 2021-11-19T09:38:14.057 回答