spring Aop概念

 

AOP概念

切面(Aspect与类很相似,切面是横切性关注点的抽象

目标对象(Target Object

AOP代理类(AOP Proxy jdk cglib

连接点(Joinpoint  被拦截到的点,指调用某方法或者处理某异常

切入点(Pointcut   匹配连接点的断言,一系列连接点的集合,它指明处理方式(Advice)将在何时被触发

通知(Advice  拦截到joinpoint之后要做的事情

前置通知(Before advice):在某连接点之前执行的通知

后置通知(After returning advice):在某连接点正常完成后执行的通知

异常通知(After throwing advice):在方法抛出异常退出时执行的通知

环绕通知(Around Advice):包围一个连接点的通知

最终通知(After (finally) advice):当某连接点退出的时候执行的通知(不论是正常返回还是异常退出)。

 

 

织入(Weaving指将aspects应用到target对象    并导致proxy对象创建      的过程  spring aop

 

execution (* com.puckasoft.dao.PhotoDao.* (..))

 

AOP配置

xmlns:aop="http://www.springframework.org/schema/aop"

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

 

加入jar

   spring-framework-2.5.6\lib\aspectj\aspectjrt.jar

   spring-framework-2.5.6\lib\aspectj\aspectjweaver

 

 

AOP xml

<aop:config>

         <aop:pointcut>                  切入点

         <aop:aspect>                    切面

                   <aop:before>            前置通知

                   <aop:after-returning>   后置通知

                   <aop:after-throwing>    异常通知

                   <aop:after>             最终通知

 

 

 

 

 

 

 

AOP注解

启用@AspectJ支持

<aop:aspectj-autoproxy/>

@Aspect

@Pointcut

 

任意公共方法的执行:

 

executionpublic * *..))

 

 

任何一个名字以“set”开始的方法的执行:

 

execution* set*..))

AccountService接口定义的任意方法的执行:

 

execution* com.xyz.service.AccountService.*..))

service包中定义的任意方法的执行:

 

execution* com.xyz.service.*.*..))

service包或其子包中定义的任意方法的执行:

 

execution* com.xyz.service..*.*..))

 

@Before                                                                   [Object arg]

@AfterReturning       pointcutreturning                     [Object  result]

@AfterThrowing                  pointcutthrowing  Exception             [Exception e]

@After

@Around 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值