bean(bean Id/bean name)
Bean(*Service)增强以service结尾的所有bean
例如 bean(customerService) 增强customerService的bean中所有方法
execution(<访问修饰符>?<返回类型>空格<方法名>(<参数>)<异常>?)
例如:
execution(* cn.yanqi.spring.a_jdkproxy.CustomerServiceImpl.*(..)) 增强bean对象所有方法
execution(* cn.yanqi.spring..*.*(..)) 增强spring包和子包所有bean所有方法
提示:最灵活的
within(包.类)
例如: within(cn.yanqi.spring..*) 增强spring包和子包所有bean“所有方法 ”
this(完整类型)/target(完整类型)
This 可以对普通类和接口类进行增强,target 可以对普通类和接口类及实现类进行增强
例如: this(cn.yanqi.spring.a_jdkproxy.CustomerService) 增强类型所有方法
【AspectJ类型匹配的通配符】
*:匹配任何的字符
…:匹配任何数量字符的重复,如在类型模式中匹配任何数量子包;而在方法参数模式中匹配任何数量参数。
+:匹配指定类型的子类型;仅能作为后缀放在类型模式后边。
例如经常使用到的匹配:(注意这里使用到了注解进行匹配的,可以只看匹配规则)
示例:
@Before("bean(*Service)")
@AfterReturning(value = "target(com.hisoft.service.impl.StudentServiceImpl))",returning = "rv")
@Around("execution(* com.hisoft.service.impl.StudentServiceImpl.*(..))")
@AfterThrowing(value="within(com.hisoft.service.impl.*)",throwing = "ex")