使用注解
- @After
- @AfterReturning
- @AfterThrowing
- @Around
- @Before
使用 javaConfig 时需要在配置类上加上 @EnableAspectJAutoProxy 注解,xml 时使用:<aop:aspectj-autoproxy>
环绕通知

args 限定符,表明床底给 play 方法的 int 型参数也会传递到通知中。


通过注解引入新功能(新方法)
- 通过 spring aop,我们可以为 bean 引入新方法
- 当引入接口的方法被调用时,代理会把此调用委托给实现了接口的某个其他对象
- 借助 aop 引入功能,我们可以不必在设计上妥协或者侵入性的改变现有的实现
@DeclareParents 注解可将新接口引入到现有 bean 中

value:指明哪种类型的 bean 要引入该接口
defaultImpl:为引入功能提供实现的类
@DeclareParents 注解的成员指明了要引入的接口
在 xml 中声明切面
<aop:advisor>
<aop:after>
<aop:after-returning>
<aop:after-throwing>
<aop:around>
<aop:aspect>
<aop:aspectj-autoproxy>
<aop:before>
<aop:config> 顶层 aop 配置元素,大多数 <aop:*>都为其子属性
<aop:declare-parents>
<aop:pointcut>

网友评论