Spring AOP

大纲

什么是AOP?

基本概念

Spring中的AOP

Schema—based AOP基于配置、文件

SpringAOP API

AspectJ


面向切面编程Aspect Oriented Programming,通过预编译和运行期动态代理实现程序功能的统一维护的一种技术

主要功能:日志记录,性能统计,安全控制,事务处理,异常处理

实现方式:预编译(如AspectJ)

运行期动态代理(JDK动态代理(有接口)、CGLib动态代理(无接口)如:SpringAOP、JbossAOP)

       提供了声明式的企业服务,特别是EJB的代替服务的使用;允许用户定制自己的方面,完成OOP与AOP的互补使用

       不提供最完整的AOP实现,侧重提供AOP和Spring IoC容器之间的整合,用于帮助企业应用中的常见问题


基本概念

切面(Aspect):the modularization of a concern thatcuts across multiple classes

连接点(Join Point):a point during the execution ofa program

通知(Advice):action taken by a aspect at aparticular join point

切入点(Pointcut):a predicate that matches joinpoint

引入(Introduction):declaring additional methodsor fields on behalf of a type

目标对象(Target Objection):object being advised byone or more aspects

AOP代理(AOP proxy):an Object created by AOP framework in order to implement the aspectcontracts

织入(Weaving):linking aspect with otherapplication types or objects to create an advised object

 

Advice:

Beforeadvice: execution before a join point, cannot break(unless throws an exception)

Afterreturning advice: after join point completes normally

Afterthrowing advice: if method exits by throwing an exception

After(finally) advice:

Aroundadvice:

 

配置:

spring-aop-schema-advice.xml

       <aop:config>

              <aop:aspect id=”” ref=””>

                     <aop:pointcut id=””expression=””/>

                     <aop:before method=””point-ref=””>

                     <aop:after-returningmethod=”” point-ref=””>

                     <aop:after-throwingmethod=”” point-ref=””>

                     <aop:after method=””point-ref=””>

                     <aop:around method=””point-ref=””>

              </aop:aspect>

       </aop:config>

 

说明:

ref:跟配置bean的id

expression: pointcut有很多规则,用的时候再看

method:aop:aspect中的方法

point-ref:aop:pointcut的id

around的参数必须是ProceedingJoinPoint

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值