Spring AspectJ Aop Annotation

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class PermissionAspect {
    //@Pointcut("execution(* cn.mwee.wpos.service..*(..))")
    @Pointcut("execution(@cn.test.annotation.Permission * *(..))")
    public void permissionPointcut() {}

    @Around("permissionPointcut()")
    public CommonResponse checkPermission(ProceedingJoinPoint joinPoint){ //ProceedingJoinPoint joinPoint
        CommonResponse response=new CommonResponse();
        try {
            // 执行的类
            String exeType = null;
            // 执行的方法
            String exeMethod = null;

            response.getErr().setErrNo(ErrorCode.NO_PERMISSION).setErrMsg(ErrorDesc.NO_PERMISSION);

            MethodSignature signature = (MethodSignature) joinPoint.getSignature();
            exeType = signature.getDeclaringType().getCanonicalName();
            exeMethod = signature.getMethod().getName();

            System.out.println(exeType + " " + exeMethod);
            return response;

            //return (CommonResponse)joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return response;
    }
}

猜你喜欢

转载自takeme.iteye.com/blog/2366513