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;
}
}
Spring AspectJ Aop Annotation
于 2017-03-29 17:08:00 首次发布
本文介绍了一个使用AspectJ实现的Spring权限验证切面。该切面通过定义切入点来拦截被特定注解标记的方法,并在其执行前后进行权限检查。文章详细展示了如何配置AspectJ切面以及如何在目标方法执行前进行权限验证。
1366

被折叠的 条评论
为什么被折叠?



