aop使用註解配置流程:
1、當spring容器啟動時候。
<
context
:component-
scan
base
-package
="cn.itheima03.spring.aop.annotation"
>
<
/context
:component-scan>
2、在上面的包及子包中查詢全部的類,依照類掃瞄註解的機制把類放入到spring容器中
3、 檢查是否配置::
aspectj-autoproxy>
<
/aop
:aspectj-autoproxy>
4、查詢哪些類上加
@aspect註解,會查詢加了該註解的全部的方法。看方法上是否有
@pointcut註解
5、把@
pointcut的切入點表示式解析出來和spring中的bean進行匹配。假設匹配成功,則建立**物件
6、生成的**物件的方法=通知+
目標方法
完整**:
<
beans
xmlns
=""xmlns:context
=""xmlns:xsi
=""xmlns:aop
=""xsi:schemalocation="
/spring-beans-2.5.xsd
/spring-context-2.5.xsd
/spring-aop-2.5.xsd"
>
<
context:component-scan
base-package
="cn.itheima03.spring.aop.annotation"
>
context:component-scan
>
<
aop:aspectj-autoproxy
>
aop:aspectj-autoproxy
>
beans
>
//配置註解,須要產生例項
@repository
("classesdao"
)public
class
classesdaoimpl
extends
hibernateutils
implements
classesdao
public
listgetclasses()
public
void
updateclasses(classes classes)
}
=============================
/**
*@aspect該注講解明該類是乙個切面類
,等效於:
* ref
="mytransaction">
*
* id="
aa()"/>
*
*/
@component
("mytransaction"
)@aspect
public
class
mytransaction
extends
hibernateutils
//方法簽名 方法的修飾符最好為private,返回值必須是void
@before
("aa()"
)public
void
begintransaction()
@afterreturning
("aa()")
public
void
commit()
}
spring 五 AOP註解學習
1 配置檔案 檔名沒有規定,可任意命名 2 建立實現類 日誌記錄實現類 基於註解的aop aspect 宣告切面類 component public class logaspect 後置增強 after execution com.zh.aop.public void afteradvice 環繞增...
Spring之AOP註解方式
註解實現aop 1.啟用aspectj支援 2.在切面類加入 component aspect 3.配置切入點表示式 4.加入增強的方法,注意 環繞增強的方法中一定要加入proceedingjoinpoint引數 5.切面優先順序用切面類實現介面 implements ordered 或 order...
Spring 使用註解配置AOP
1.配置切點 切點 component預設是類名首字母小寫,也可以寫成 component demo123 進行自定義 author barrylee 2018年11月14日 上午8 50 51 component demo123 public class demo 2.配置通知 通知 compon...