首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用JDBC feeder连接到带有Windows身份验证的SQL Server的Gatling引发错误"java.lang.NoSuchMethodError“

使用JDBC feeder连接到带有Windows身份验证的SQL Server的Gatling引发错误"java.lang.NoSuchMethodError“
EN

Stack Overflow用户
提问于 2020-12-16 06:43:25
回答 1查看 352关注 0票数 0

从这个documentation中学习,我尝试使用Gatling JDBC feeder从带有Windows身份验证的SQL Server中获取数据。

我在POM.xml中添加了这个依赖项

代码语言:javascript
运行
复制
<!-- https://mvnrepository.com/artifact/dev.code-n-roll.gatling/jdbc-gatling -->
<dependency>
  <groupId>dev.code-n-roll.gatling</groupId>
  <artifactId>jdbc-gatling_2.12</artifactId>
  <version>2.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.gatling/gatling-jdbc -->
<dependency>
  <groupId>io.gatling</groupId>
  <artifactId>gatling-jdbc</artifactId>
  <version>3.4.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
  <groupId>com.microsoft.sqlserver</groupId>
  <artifactId>mssql-jdbc</artifactId>
  <version>7.4.1.jre8</version>
</dependency>

我的连接字符串如下所示

代码语言:javascript
运行
复制
import io.gatling.jdbc.Predef._

val databaseUrl = "jdbc:sqlserver://CentralSQLServer:1433;databaseName=CustomerDB;integratedSecurity=true"

我添加integratedSecurity=true是因为对SQL server的访问方法是使用Windows身份验证,而不是使用用户名和密码。当我将vanilla Java与JDBC一起使用时,它工作得很好。

然后,我定义了JDBC馈送器。

代码语言:javascript
运行
复制
val mySQLFeeder = jdbcFeeder(databaseUrl, "", "", "SELECT * FROM [CustomerDB].[dbo].[Users]")

我在用户名和密码部分放入了空字符串,因为我没有它。

使用mvn gatling:test运行Gatling测试,我发现这个错误是由Gatling抛出的

代码语言:javascript
运行
复制
02:05:29.920 [ERROR] i.g.a.Gatling$ - Run crashed
java.lang.NoSuchMethodError: io.gatling.core.feeder.SourceFeederBuilder$.apply(Lio/gatling/core/feeder/FeederSource;Lio/gatling/core/config/GatlingConfiguration;)Lio/gatling/core/feeder/SourceFeederBuilder;
    at io.gatling.jdbc.Predef$.jdbcFeeder(Predef.scala:26)
    at testCases.Delete.<init>(Delete.scala:49)
    ... 16 common frames omitted
Wrapped by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at io.gatling.app.Runner.run0(Runner.scala:74)
    at io.gatling.app.Runner.run(Runner.scala:60)
    at io.gatling.app.Gatling$.start(Gatling.scala:80)
    at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
    at io.gatling.app.Gatling$.main(Gatling.scala:38)
    at io.gatling.app.Gatling.main(Gatling.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at io.gatling.app.Runner.run0(Runner.scala:74)
    at io.gatling.app.Runner.run(Runner.scala:60)
    at io.gatling.app.Gatling$.start(Gatling.scala:80)
    at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
    at io.gatling.app.Gatling$.main(Gatling.scala:38)
    at io.gatling.app.Gatling.main(Gatling.scala)
    ... 6 more
Caused by: java.lang.NoSuchMethodError: io.gatling.core.feeder.SourceFeederBuilder$.apply(Lio/gatling/core/feeder/FeederSource;Lio/gatling/core/config/GatlingConfiguration;)Lio/gatling/core/feeder/SourceFeederBuilder;
    at io.gatling.jdbc.Predef$.jdbcFeeder(Predef.scala:26)
    at testCases.Delete.<init>(Delete.scala:49)
    ... 16 more

因为在文档中我们应该使用用户名和密码,所以看起来Gatling JDBCFeeder方法使用integratedSecurity=true报告了我的连接字符串。问题是在我的例子中没有用户名和密码。

有没有办法解决这个问题?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-12-16 21:12:27

感谢@乔治·梁和@斯蒂芬妮·兰德尔。

该问题是由依赖项版本冲突引起的。gatling-jdbc版本必须与gatling-core版本保持一致。

将POM.xml中的依赖项更改为下面所示确实可以解决此问题。

代码语言:javascript
运行
复制
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.3.1</gatling.version>
    <gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>
    <scala-maven-plugin.version>4.3.1</scala-maven-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    <scala.version>2.12.10</scala.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.gatling.highcharts</groupId>
        <artifactId>gatling-charts-highcharts</artifactId>
        <version>${gatling.version}</version>
    </dependency>

    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-app</artifactId>
        <version>${gatling.version}</version>
    </dependency>

    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-recorder</artifactId>
        <version>${gatling.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>7.4.1.jre8</version>
    </dependency>

</dependencies>

gatling-app包含gatling-jdbc,所以我们不需要额外添加它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65314767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档