在aop切面中拿到方法和方法的註解

private Media getMethodAnnotation(ProceedingJoinPoint pjp)
            throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
        MethodInvocationProceedingJoinPoint methodPjp = (MethodInvocationProceedingJoinPoint) pjp;
        Field field = methodPjp.getClass().getDeclaredField("methodInvocation");
        field.setAccessible(true);
        ProxyMethodInvocation invocation = (ProxyMethodInvocation) field.get(methodPjp);
        Media media = invocation.getMethod().getAnnotation(Media.class);
        return media;
    }get

此處 Media 是自定義註解it

 拿到方法io

   Signature signature = pjp.getSignature();
   MethodSignature methodSignature = (MethodSignature) signature;
   Method targetMethod = methodSignature.getMethod();class

相關文章
相關標籤/搜索