JMeter调用Azure Key Vault遇NoClassDefFoundError问题求助
JMeter读取Azure Key Vault凭证报错问题
个人说明
我来自测试领域,对开发侧的库、类、方法较为陌生,恳请谅解。
问题背景
我们正在用JMeter编写负载测试脚本,需要将测试登录凭证存储在Azure Key Vault中,让脚本运行时从中读取凭证。为此在JSR223前置处理器里用Groovy编写了代码,但运行时出现错误。
运行环境
- JMeter:最新版本
- Java版本:17
- 操作系统:Windows
已尝试操作
根据网上资料,已将以下JAR包添加至JMeter库,但问题仍未解决:
- Azure-common 1.8.0
- Azure-core 1.53.0
- Azure-identity 1.13.3
- Azure-security-keyvault-secrets 4.8.6
- msal4j 1.13.3
代码及错误详情
Groovy代码(JSR223前置处理器中)
import com.azure.identity.DefaultAzureCredentialBuilder import com.azure.security.keyvault.secrets.SecretClientBuilder def SecretName = "mysecretname"; def keyVaultName = "myVaultName"; def keyVaultUri = "https://${keyVaultName}.vault.azure.net/"; def credential = new DefaultAzureCredentialBuilder().build() // 错误行 def client = new SecretClientBuilder().vaultUrl(keyVaultUri).credential(credential).buildclient() def secretvalue = client.getSecret(SecretName).getValue() vars.put("password",password)
错误日志(来自JMeter日志查看器)
ERROR o.a.j.JMeter: Uncaught exception in thread Thread[] java.lang.NoClassDefFoundError: Could not initialize class com.azure.identity.implementation.RegionalAuthority at com.azure.identity.implementation.IdentityClientOptions.<init> (IdentityClientOptions.java:99) ~[azure-identity-1.13.3.jar:1.13.3] at com.azure.identity.CredentialBuilderBase.<init>(CredentialBuilderBase.java:47) ~[azure-identity-1.13.3.jar:1.13.3] at com.azure.identity.DefaultAzureCredentialBuilder.<init>(DefaultAzureCredentialBuilder.java:77) ~[azure-identity-1.13.3.jar:1.13.3] ..... Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.BootstrapMethodError: java.lang.SecurityException: class "com.azure.core.implementation.ReflectiveInvoker"'s signer information does not match signer information of other classes in the same package [in thread "Login-Logout 1-1"] at com.azure.core.util.ExpandableStringEnum.fromString(ExpandableStringEnum.java:70) ~[azure-core-1.53.0.jar:1.53.0] at com.azure.identity.implementation.RegionalAuthority.fromString(RegionalAuthority.java:287) ~[azure-identity-1.13.3.jar:1.13.3] ..
解决方法
清理冲突JAR包
错误提示签名信息不匹配,说明JMeter库中存在版本冲突或重复类。先清空lib和lib/ext目录下所有Azure相关旧JAR,避免不同版本类互相干扰。使用兼容依赖版本组合
Azure SDK各组件版本需严格兼容,建议通过Maven/Gradle获取完整依赖链,确保所有关联JAR版本匹配。推荐组合:- Azure-core: 1.54.0
- Azure-identity: 1.14.0
- Azure-security-keyvault-secrets: 4.9.0
注意要引入所有依赖包(如azure-core-http-netty、jackson系列JAR等),不要仅手动添加主JAR。
修正代码错误
代码存在两处明显问题:buildclient()需改为buildClient()(Groovy对方法名大小写敏感);vars.put("password",password)中password未定义,应替换为secretvalue。
修正后代码:
import com.azure.identity.DefaultAzureCredentialBuilder import com.azure.security.keyvault.secrets.SecretClientBuilder def secretName = "mysecretname"; def keyVaultName = "myVaultName"; def keyVaultUri = "https://${keyVaultName}.vault.azure.net/"; def credential = new DefaultAzureCredentialBuilder().build() def client = new SecretClientBuilder().vaultUrl(keyVaultUri).credential(credential).buildClient() def secretValue = client.getSecret(secretName).getValue() vars.put("password", secretValue)验证身份配置
DefaultAzureCredential依赖本地Azure身份配置,确保Windows机器已完成身份验证(如通过Azure CLI执行az login登录、设置对应环境变量,若在Azure虚拟机上运行可使用托管身份)。
内容的提问来源于stack exchange,提问作者Navjot3019
相关产品推荐
相关产品推荐

