1、AspectJ的概念:AspectJ是一个面向切面的框架,它扩展了Java语言。AspectJ定义了AOP语法所以它有一个专门的编译器用来生成遵守Java字节编码规范的Class文件。
2、AspectJ表达式:
* 语法:execution(表达式)
execution(<访问修饰符>?<返回类型><方法名>(<参数>)<异常>)
* execution(* cn.itcast.spring3.demo1.dao.*(..)) ---只检索当前包
* execution(* cn.itcast.spring3.demo1.dao..*(..)) ---检索包及当前包的子包.
* execution(* cn.itcast.dao.GenericDAO+.*(..)) ---检索GenericDAO及子类
3、AspectJ增强:
@Before 前置通知,相当于BeforeAdvice
@AfterReturning 后置通知,相当于AfterReturningAdvice
@Around 环绕通知,相当于MethodInterceptor
@AfterThrowing抛出通知,相当于ThrowAdvice
@After 最终final通知,不管是否异常,该通知都会执行
@DeclareParents 引介通知,相当于IntroductionInterceptor