You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazemeter运行JMeter脚本时JSR223 Groovy报MissingMethodException错误

报错原因
  • 语法版本不兼容:你在第二个Groovy脚本中使用了var关键字声明变量,该关键字是Groovy 3.0及以上版本才支持的动态类型声明语法。从报错日志可确认Blazemeter环境使用的Groovy版本为2.4.16,无法识别var关键字,会将其误判为方法名调用,因此抛出MissingMethodException异常。你本地JMeter内置的Groovy版本更高,所以本地运行无报错。
  • 代码冗余:JMeter的所有JSR223组件默认已内置props全局变量,可直接调用访问JMeter属性,无需手动执行org.apache.jmeter.util.JMeterUtils.getJMeterProperties()重复获取。
解决方案

直接删除第二个JSR223 PostProcessor(Retrieve Tasks)中var props = org.apache.jmeter.util.JMeterUtils.getJMeterProperties();这一行代码即可,修改后的完整脚本如下:

import groovy.json.JsonSlurper;

JsonSlurper JSON = new JsonSlurper ();

def failureMessage = "";
def tasks = null;

try {
     tasks = JSON.parseText(props.get("tasks"));
    for (i = 0; i < tasks.size(); i++) {
            vars.put("taskId" + i.toString(), tasks[i].id.toString());
            vars.put("taskTag" + i.toString(), tasks[i].sourceTag.toString());
    }
    vars.put("taskCount", tasks.size().toString());
} catch (Exception e) {
    failureMessage += "Invalid JSON.\n";
    log.info(e.toString());
}
优化建议

如果需要保证脚本在不同JMeter/Groovy版本环境下的兼容性,尽量避免使用高版本Groovy新增的语法特性,优先使用Groovy 2.x支持的def关键字声明动态类型变量。

内容的提问来源于stack exchange,提问作者Josh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 14:15:00