簡體   English   中英

如何輕松找到哪些端點調用了方法?

[英]How to easily find which endpoints call a method?

我有一個包含許多端點的應用程序。 我對 functionWhoIsCallingMe() 進行了更改。 我想找到哪個 controller 端點調用這個 function(直接或分層),以便我可以測試它。

@RequestMapping("/a")
someEndpoint(){
 anyFunction()
}

@RequestMapping("/b")
anotherEndpoint(){
 functionWhoIsCallingMe()
}

anyFunction(){
  functionWhoIsCallingMe()
}

鑒於此代碼,我想知道 ["/a", "/b"] 正在調用 functionWhoIsCallingMe()。

我嘗試了“調用層次結構”,但這在這里不實用,因為打開所有選項卡需要很長時間。 我也嘗試過這里建議的過濾,但這不起作用,因為您只能指定一種類型的 class 不匹配,如果不匹配,則不會顯示調用方法。 我不能說只顯示文件名中帶有 Controller 的文件。

@RequestMapping("/b")
public void someEndpoint() {
    anyFunction(1);
}
@RequestMapping("/b")
public void anotherEndpoint() {
    functionWhoIsCallingMe(1);
}

public void anyFunction(int val/** init val=1*/) {
    functionWhoIsCallingMe(val + 1);
}

public void functionWhoIsCallingMe(int val/** init val=1*/) {
    try {
        final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
        String defName = ste[val + 1].getMethodName();
        String[] path = this.getClass().getMethod(defName).getAnnotation(RequestMapping.class).value();
        System.out.println("Url path:" + path[0]);
    } catch (Exception ex) {
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM