Spring之面向方面编程(AOP)

来源:互联网 发布:阿里云域名管理地址 编辑:程序博客网 时间:2024/05/18 14:25

定义

面向方面编程:Aspect Oriented Programming

  AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程。可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术。AOP实际是GoF设计模式的延续。

Spring AOP Advice

1.Before Advice:在执行目标操作之前执行的装备(Advice)。在Spring中实现为org.springframework.aop.MethodBeforeAdvice

2.Throws Advice:如果目标操作在执行过程中抛出了异常,则执行该装备。在Spring中实现为org.springframework.aop.AfterReturningAdvice

3.After Advice:在执行目标操作之后执行的装备。在Spring中实现为org.springframework.aop.ThrowsAdvice

4.Around Advice:在方法调用前后执行的装备。这种装备功能最强大。在Spring中实现为org.springframework.aop.MethodInterceptor

5.Introduction AdviceIntroduction装备能够为类新增方法,是最复杂的装备。

原创粉丝点击