使用AspectJ的AOP開發
AspectJ它是一個開源的第三方的AOP 框架,spring 把它集成進來了
一、Apsectj的AOP(XML方式)
1. 創建項目並導包
2. 創建目標類
3. 創建applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 導入頭文件 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
</beans>
4. 前置通知
- 創建MyAdvise
- 配置applicationContext.xml
- 測試
5. 後置通知
- MyAdvise
- 配置applicationContext.xml
- 測試
6. 環繞通知
|-- 第一種環繞通知
- MyAdvise
- 配置applicationContext.xml
- 測試
|-- 第二種環繞通知 - 修改MyAdvice
- 配置applicationContext.xml
- 測試
7. 異常通知
- 修改MyAdvise
- 配置applicationContext.xml
- 測試
二、Aspectj的AOP(註解方式)
1. 創建Person
2. 創建MyAdvise
3. 創建applicationContext.xml
4. 前置增強
- 修改MyAdvise
5. 後置增強
- 修改MyAdvise
6. 環繞增強
- 修改MyAdvise
7. 異常增強
- 修改MyAdvise
- 修改Person