Spring_14_AOP_註解配置

前文:Spring_13_AOP_基本概念和xml配置

 

xml配置文件中

配置AOP的自動代理

<aop:aspectj-autoproxy />

 

AOP相關注解

· @Aspect

標註在類上。聲明該類爲切面。即增強類。

該類必須有對應的bean配置。

相當於

<aop:aspect ref = "bean id">

 

· @Pointcut

要結合切點簽名方法使用。

@Pointcut("execution(* com.hanaii.aop.*Service.*(..))")
public void txPoint(){}

相當於

<aop:pointcut expression="execution(* hanaii.com.aop.*Service.*(..))" id="txPointcut">

 

· 增強類型相關標籤

以@AfterReturning爲例。標註在方法上

該標籤value屬性值爲切點方法的簽名。相當於<aop:after-returning>的point-ref屬性。

@AfterReturning("txPointcut()")

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章