Pointcut匹配条件
Advice匹配后执行操作
/**
* //匹配任何公共方法
*
* @Pointcut("execution(public * com.imooc.service.*.*(..))")
* <p>
* //匹配com.imooc包及子包下Service类中无参方法
* @Pointcut("execution(* com.imooc..*Service.*())")
* <p>
* //匹配com.imooc包及子包下Service类中的任何只有一个参数的方法
* @Pointcut("execution(* com.imooc..*Service.*(*))")
* <p>
* //匹配com.imooc包及子包下任何类的任何方法
* @Pointcut("execution(* com.imooc..*.*(..))")
* <p>
* //匹配com.imooc包及子包下返回值为String的任何方法
* @Pointcut("execution(String com.imooc..*.*(..))")
* <p>
* //匹配异常
* execution(public * com.imooc.service.*.*(..) throws java.lang.IllegalAccessException)
* <p>
* Created by cat on 2017-02-19.
*/
@Aspect
@Component
public class ExecutionAspectConfig {
// Pointcut匹配条件
@Pointcut("execution(public * com.imooc.service..*Service.*(..) throws java.lang.IllegalAccessException)")
public void matchCondition() {
}
// 匹配后执行策略
@Before("matchCondition()")
public void before() {
System.out.println("");
System.out.println("###before");
}
}
/**
* //匹配AOP对象的目标对象为指定类型的方法,即LogService的aop代理对象的方法
* @Pointcut("this(com.imooc.log.Loggable)")
* //匹配实现Loggable接口的目标对象(而不是aop代理后的对象)的方法
* @Pointcut("target(com.imooc.log.Loggable)")
* //this 可以拦截 DeclareParents(
* Introduction)
* //target 不拦截 DeclareParents(Introduction)
* //匹配所有以Service结尾的bean里头的方法
* @Pointcut("bean(*Service)")
* Created by cat on 2016-12-04.
*/
introduction
execution
修饰符
返回类型
包名
描述方法名(描述方法参数)
抛出异常类型
?表示可以省略