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()")