SpringAOP aspectJ ProceedingJoinPoint 獲取當前方法


  

aspectJ切面通過ProceedingJoinPoint想要獲取當前執行的方法:

錯誤方法:

 

     Signature s = pjp.getSignature();
    MethodSignature ms = (MethodSignature)s;
    Method m = ms.getMethod();

這種方式獲取到的方法是接口的方法而不是具體的實現類的方法,因此是錯誤的。

 

正確方法:

        Signature sig = pjp.getSignature();
        MethodSignature msig = null;
        if (!(sig instanceof MethodSignature)) {
            throw new IllegalArgumentException("該注解只能用於方法");
        }
        msig = (MethodSignature) sig;
        Object target = pjp.getTarget();
        Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());

 

Spring 之AOP AspectJ切入點語法詳解

  https://blog.csdn.net/zhengchao1991/article/details/53391244

使用AspectJ編程

  https://blog.csdn.net/zl3450341/article/details/7673938


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM