aspectj 獲取 連接點 方法!


public static Method getMethod(JoinPoint joinPoint) {
        Method method = null;
        String name = joinPoint.getSignature().getName();

        try {
        // 這才是 正統! MethodSignature signature = (MethodSignature) joinPoint.getSignature();
            Class[] types = signature.getParameterTypes();

            joinPoint.getSignature();
            method = joinPoint.getTarget(). getClass().getMethod(name,types);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return method;
    }

 多個連接點--

@Before("@annotation(cloud.cjy.travel.module.common.annotation.CjyAspect) || within(@cloud.cjy.travel.module.common.annotation.CjyAspect *)")

或者:
 
         
private static MethodSignature getMethodSignature(JoinPoint joinPoint) {
Signature signature = joinPoint.getSignature();
return (MethodSignature) signature;
}



public
static Method getMethod(JoinPoint joinPoint) { MethodSignature methodSignature = getMethodSignature(joinPoint); return methodSignature.getMethod(); }


免責聲明!

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



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