對(duì)切面和切入點(diǎn)的理解
<aop:config> ????<aop:aspect?id="myAspect"?ref="aBean"> ????<aop:pointcut?expression="execution(*?com.imooc.aop.schema.advice.biz.*Biz.*(..))"?id="moocPointcut"?/> ????<aop:before?method="before"?pointcut-ref="moocPointcut"?/>?//前置通知 ????<aop:after-returning?method="afterReturning"?pointcut-ref="moocPointcut"?/>?//返回后通知 ????<aop:after-throwing?method="afterThrowing"?pointcut-ref="moocPointcut"?/>?//拋出異常后通知 ????<aop:after?method="after"?pointcut-ref="moocPointcut"?/>?//后通知 ????</aop:aspect> </aop:config>
aspect引用的類aBean相當(dāng)于一個(gè)切面,里面提供處理切入點(diǎn)的方法,pointcut里的expression相當(dāng)于一個(gè)生產(chǎn)線,里面的各個(gè)方法就相當(dāng)于生產(chǎn)線的切入點(diǎn)。之后的after,after-throwing,before相當(dāng)于不同切入點(diǎn)的工人,通過(guò)ponitcut-ref到指定切入點(diǎn)工作,只不過(guò)工作時(shí)間順序不同,分別在切入點(diǎn)后,出問題后,切入點(diǎn)前,method表示程序順著生產(chǎn)線到切入點(diǎn)時(shí)各個(gè)工人用切入面的方法處理。
2019-05-20
寫的挺好的,理解感覺也挺生動(dòng)。
定義了一個(gè)方面,每個(gè)方面會(huì)有若干點(diǎn),每個(gè)點(diǎn)都可以設(shè)置在什么時(shí)候觸發(fā)這個(gè)點(diǎn)開始工作,分別可以設(shè)置在這個(gè)點(diǎn)發(fā)生的事件之前、之后、返回前、拋出異常之前。同時(shí)也設(shè)置了各個(gè)方法,一點(diǎn)觸發(fā)就到對(duì)應(yīng)的方法中執(zhí)行相應(yīng)的操作。
總體感覺大概就是這個(gè)意思。