使用spring Aop 切日誌 日誌管理

2021-09-07 20:12:17 字數 1342 閱讀 8126

先看效果圖下面是資料庫的儲存操作日誌:

配置檔案:

工具類:

public object around(proceedingjoinpoint pjp) throws throwable 

//方法通知前獲取時間,為什麼要記錄這個時間呢?當然是用來計算模組執行時間的

long start = system.currenttimemillis();

system.out.println(start+"**********==");

log.setlog_starttime(new date(start));

// 攔截的實體類,就是當前正在執行的service

object target = pjp.gettarget();

log.setlog_nameclass(target.tostring());

// 攔截的方法名稱。當前正在執行的方法

string methodname = pjp.getsignature().getname();

log.setlog_namemethod(methodname);

// 攔截的方法引數

object args = pjp.getargs();

// 攔截的放引數型別

signature sig = pjp.getsignature();

methodsignature msig = null;

if (!(sig instanceof methodsignature))

msig = (methodsignature) sig;

class parametertypes = msig.getmethod().getparametertypes();

object object = null;

// 獲得被攔截的方法

method method = null;

try catch (nosuchmethodexception e1) catch (securityexception e1)

system.out.println(log.getlog_namemethod()+"*****");

if (null != method) catch (throwable e)

} else

} else

return object;

}

使用Spring AOP記錄訪問日誌

api class clazz joinpoint.gettarget getclass 獲取目標類物件 string methodname joinpoint.getsignature getname 獲取切入點的方法名 string values anno.value 獲取註解的value屬性值...

使用springAop實現日誌審計

記錄一次通過springaop實現審計日誌功能的需求實現 所謂審計日誌,就是把所有使用者的操作都要記錄下來,防止系統出問題了,追溯責任人 實現該功能的幾步 1.首先使用 aspect定義乙個切面類logaspect 2.在切面類裡面使用 pointcut annotation com.aaa.bbb...

Spring AOP 基於Schema配置切面

廢話不多說,直接通過乙個demo來看一下吧,這裡我們需要將spring的aop命名空間加入到配置檔案中。spring配置如下 增強類advicemethod public class advicemethod 場景呼叫如下 public class client 輸出了我們想要的效果 how are...