// 这种方式获取的话,数组的第一个元素是当前运行方法的名称,第二个元素是调用当前方法的方法名称
StackTraceElement[] stackTrace = new Exception().getStackTrace(); String methodName = stackTrace[0].getMethodName(); 
// 这种方式获取的话,数组的第二个元素是当前运行方法的名称,第三个元素是调用当前方法的方法名称
stackTrace = Thread.currentThread().getStackTrace(); methodName = stackTrace[1].getMethodName(); 
StackTraceElement[] stackTrace1 = new Exception().getStackTrace();
String methodName;
if (stackTrace1 != null && stackTrace1.length > 0){
methodName = stackTrace1[1].getMethodName();
}
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
methodName = stackTrace[2].getMethodName();
return methodName;
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。