在 class'org.apache.log.Logger' 中未找到方法信息 ( java.util.HashMap )

Method info( java.util.HashMap ) not found in class'org.apache.log.Logger'

 log.info(m.differenceValue(jsonElement1,jsonElement2)); 

从 beanshell 调用函数。 jar文件中实现的代码。

public static <K, V> Map<String,Object> differenceValue(JsonElement json1, JsonElement json2){
    Gson g = new Gson();

    Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
    Map<String,Object> firstMap = g.fromJson(json1, mapType);
    Map<String, Object> secondMap = g.fromJson(json2, mapType);
   return(mapDifference(firstMap,secondMap));
}      
public static <K, V> Map<K, V> mapDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) {
    Map<K, V> difference =  new HashMap<K, V>();
    difference.putAll(left);
    difference.putAll(right);
    difference.entrySet().removeAll(right.entrySet());
    return difference;
}

在 eclipse 中工作正常,但在 jmeter 中它抛出

error:Method info( java.util.HashMap ) not found in class'org.apache.log.Logger'

您正在尝试将 Map 传递给 Logger while it accepts only Strings for info(), warn() 等方法,您需要以某种方式将 Map 转换为 String。

此外,我认为 Beanshell 中不支持泛型,请考虑改用 JSR223 Elements and Groovy language

尝试log.info(m.differenceValue(jsonElement1,jsonElement2).toString());

根据文档,这可能适用于 HashMap(取决于您对那里的键和值有什么)

public String toString()

Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object).