Java 方法实现的切入点
我创建了一个带有指向注释方法的切入点的方面。作为Java 方法实现的切入点,java,spring,aspectj,spring-aop,Java,Spring,Aspectj,Spring Aop,我创建了一个带有指向注释方法的切入点的方面。作为JoinPoint我得到的是来自接口的方法声明,而不是方法实现。所以,当我想要得到带注释的方法参数时,我必须在接口中而不是在实现中添加注释 @AfterReturning(value = "@annotation(pl.styall.scylla.security.authorization.acl.AclSecure) && @annotation(aclSecure)", argNames = "jp,aclSecure,ret
JoinPoint
我得到的是来自接口的方法声明,而不是方法实现。所以,当我想要得到带注释的方法参数时,我必须在接口中而不是在实现中添加注释
@AfterReturning(value = "@annotation(pl.styall.scylla.security.authorization.acl.AclSecure) && @annotation(aclSecure)", argNames = "jp,aclSecure,retVal", returning = "retVal")
public void addObjectAndEntry(JoinPoint jp, AclSecure aclSecure,
Object retVal) {
System.out.println(jp.toLongString());
MethodSignature signature = (MethodSignature) jp.getSignature();
Method method = signature.getMethod();
Annotation[][] methodAnnotations = method.getParameterAnnotations();
methodAnnotations
如果是外接程序方法实现,则没有注释。正确的切入点是什么
final String methodName = pjp.getSignature().getName();
final MethodSignature methodSignature = (MethodSignature)pjp.getSignature();
Method method = methodSignature.getMethod();
if (method.getDeclaringClass().isInterface()) {
method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
}
资料来源: