[英]How can Spring AOP matches annotation on interface method?
I use mybatis. 我用mybatis。 My question is how can Spring AOP matches annotation on interface method?
我的问题是Spring AOP如何在接口方法上匹配注释? Because I want to put some param in annotation and then handle them in afterReturning method.
因为我想在批注中放入一些参数,然后在afterReturning方法中处理它们。
my annotation: 我的注释:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CacheClear {
String key() default "";
}
in mapper class: 在mapper类中:
@CacheClear
List<BizInst> selectAllBizInsts();
and in my aspect: 就我而言:
when use "execute..." it works 当使用“执行...”时
@AfterReturning("execution(public * com.dao.*.select*(..))")
public void doAfterReturning(){
System.out.println("after returning");
}
but when use "@annotation(...)" it doesn't work 但是当使用“ @annotation(...)”时,它不起作用
@AfterReturning("@annotation(com.annotation.CacheClear)")
public void doAfterReturning(){
System.out.println("after returning");
}
You can do something like that for selecting your public dao methods annotated with CacheClear annotation: 您可以执行类似的操作来选择使用CacheClear注释注释的公共dao方法:
@Pointcut("execution(@com.yourPackage.CacheClear * *(..))")
public void methodAnnotatedWithCacheClear( ) {}
@Pointcut("execution(public * com.dao.*.select*(..))")
public void publicDAOMethod() {}
@AfterReturning(pointcut = "methodAnnotatedWithCacheClear() && publicDAOMethod()", returning = "result")
public void doStuff(JoinPoint joinPoint, Object result) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.