**1.MyAdvice2 **
~~~
public class MyAdvice2 {
//處理連接點
public Object around(ProceedingJoinPoint pjp){
Object o = null;
try{
System.out.println("環繞通知-前置");
o = pjp.proceed();//執行被代理對象方法
System.out.println("環繞通知-后置");
}catch(Throwable throwable){
throwable.printStackTrace();
System.out.println("異常通知");
}finally {
System.out.println("環繞通知-最終");
}
return o;
}
}
~~~
**2.配置信息**
~~~
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<!--注冊目標對象-->
<bean name="userService" class="com.nobb.service.UserServiceImpl"></bean>
<!--注冊通知對象-->
<bean name="myAdvice" class="com.nobb.advice.MyAdvice2"></bean>
<aop:config>
<!--定義切點-->
<!--任意返回值 com.nobb.service 包下的任意 ServiceImpl結尾的 任意方法 任意參數-->
<aop:pointcut id="myPC" expression="execution(* com.nobb.service.*ServiceImpl.*(..))"/>
<aop:aspect ref="myAdvice">
<!--環繞切面:切點+環繞通知-->
<aop:around method="around" pointcut-ref="myPC"/>
</aop:aspect>
</aop:config>
</beans>
~~~
**3.測試代碼**
~~~
package com.test;
import com.nobb.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext2.xml")
public class AopDemo {
//byName
@Resource(name="userService")
private UserService userService;
@Test
public void fun1(){
userService.save();
}
}
~~~
**4.測試結果**
環繞通知-前置
save()
環繞通知-后置
環繞通知-最終
- mybatis
- 基礎
- maven依賴
- 主配置文件
- 實體映射表
- Mapper接口
- xxxMapper.xml
- 代碼測試
- CURD
- 查詢操作
- 新增操作
- 修改操作
- 刪除操作
- 生命周期&作用域
- 實體類型配置別名
- 進階查詢
- 列名與屬性名不對應
- 多條件sql查詢
- 模糊查詢
- 獲取保存后的主鍵
- 動態sql
- where配合If
- where配合choose
- where配合foreach
- Sql片段
- 關聯查詢
- 表結構設計及實體類
- 多對一&一對一
- 一對多
- 多對多
- 嵌套查詢(多條sql)
- 多對一&一對一
- 一對多
- 多對多
- 加載策略
- 緩存
- 一級緩存
- 二級緩存
- 配置進階
- properties
- mapper注冊
- 連接池
- 注解開發
- spring
- 基礎
- maven依賴
- bean創建
- 基礎配置
- 測試代碼
- 簡單原理
- 構造方法創建對象
- 靜態工廠創建對象
- 動態工廠創建對象
- 作用域
- 初始化&銷毀方法
- 單例和原型作用域
- 依賴注入
- 構造方法注入
- set方法注入
- 集合&數組屬性注入
- 配置文件模塊化
- 注解配置
- 配置相關
- 注解釋義
- 純注解配置
- 小結
- Spring整合junit
- 依賴管理
- 使用
- Aop
- 依賴管理
- 配置相關
- aopDemo(非環繞通知)
- 名詞解釋
- 環繞通知
- xml混合注解Aop開發
- 純注解Aop
- Aop事務
- 代理相關
- 動態代理觀光代碼
- cglib代理觀光代碼
- SpringMVC
- 基礎
- 依賴管理
- 配置web.xml
- spring-mvc.xml
- idea tomcat配置
- Hello Controller
- Api解析
- @Controller
- @RequestMapping
- 編碼問題解決
- 獲取請求頭信息
- 獲取Cookie的值
- json相關
- 依賴管理
- 接收json請求參數
- 以json形式返回給客戶端
- restful風格
- 轉發
- 重定向
- 頁面傳值
- Request域
- Session域
- Aop異常處理
- 攔截器
- 番外篇
- Tomcat
- Servlet
- 創建
- 線程安全問題
- 生命周期相關
- Filter
- Listener
- ssm整合
- mybatis基礎篇
- mybatis依賴
- mybatis實體
- Mapper接口
- mybatis配置
- 測試代碼
- spring基礎篇
- 依賴
- AccountService接口
- AccountServiceImpl
- 測試代碼
- springmvc
- 依賴
- web.xml
- spring-mvc.xml
- AccountController
- spring整合mybatis
- 依賴
- 配置
- spring整合springmvc
- web.xml
- SpringBoot
- maven配置
- 引入SpringBoot技術
- 入口及測試控制器
- 打包插件
- 配置相關
- 配置實踐
- 配置自動適配
- 配置校驗
- 配置文件制定
- SpringBoot整合Junit
- 整合mybatis
- 依賴管理
- 配置相關
- @Mapper
- 整合freemarker
- 依賴管理
- 配置相關
- 測試控制器
- 目錄相關
- 驗證器
- maven依賴
- 驗證器定義
- 控制器接收參數
- 全局異常通知
- filter跨域解決方案
- 模板相關問題
- 上傳解決方案
- redis相關
- maven依賴管理
- 配置相關
- cache簡單封裝
- json處理
- SpringCloud
- 簡介
- 版本號
- eureka
- 簡介
- 組件
- eureka服務依賴
- eureka配置
- 項目啟動
- 父類依賴庫
- eureka_cli
- eureka客戶端依賴
- 配置項
- 啟動項
- eureka集群原理
- ribbon
- maven
- 配置
- 微服務實戰
- 項目架構
- 基類依賴
- eureka注冊中心
- 1依賴相關
- 2.配置相關
- 3.啟動項
- 業務service
- supergo-manager-service
- 依賴
- 配置
- 數據源監控
- 啟動項
- feign調用
- supergo-manager-feign
- 依賴
- 調用代碼
- 接口層
- supergo-manager-web
- 依賴
- 配置項
- 啟動項
- 通用mapper
- 逆向工程
- 數據庫連接配置
- 逆向工程配置
- 操作
- base-service
- 簡介
- 跨域
- 網關層
- zuul
- 依賴項
- 配置
- 啟動項