AspectJ使用經驗

2021-04-01 04:22:12 字數 903 閱讀 8215

aspectj使用經驗

/*** @author hongsoft

* */

public aspect monitoraspect

private static ******dateformat sdf=new ******dateformat("yyyy-mm-dd hh:mm:ss");

//log logg = logfactory.getlog(monitoraspect.class);

//logger logg=logger.getlogger(monitoraspect.class.getname());

long begintime=0;

//天氣預報

pointcut monitoraspect1(): target(querywerthercachedtest)&&call(* getweatherinfobycity(string));

//**

pointcut monitoraspect4():call(*phoneservice.open(string,int,string));

private void before(string str)

private void after(string str)

object around():monitoraspect1()catch(exception e)

after("querywerthercached.getweatherinfobycity(string))");

return null;

}    

void around():monitoraspect4()catch(exception e)

after("phoneservice.open(string,int,string)");          }}

使用aspectj宣告事務

下面我們來看看aspectj 宣告事務 前面兩種宣告式事務配置方式奠定了 spring 宣告式事務管理的基石。在此基礎上,spring 2.x 引入了 命名空間,結合使用 命名空間,帶給開發人員配置宣告式事務的全新體驗,配置變得更加簡單和靈活。另外,得益於 命名空間的切點表示式支援,宣告式事務也變得...

Spring 基於AspectJ使用註解配置AOP

1.spring 不會自動去尋找註解,必須告訴 spring 哪些包下的類中可能 有註解 1.1 引入 xmlns context 2.component 2.1 相當於 2.2 如果沒有引數,把類名首字母變小寫,相當於 2.3 component 自定義名稱 3.實現步驟 3.1 在 spring...

Spring中使用AspectJ萬用字元 邏輯運算子

前言 本篇是spring核心知識系列的最後一篇,下次就要開始springboot相關的更新。雖然已經使用springboot有一段時間,但我覺得還是有必要先從spring聊起。所以我把spring相關知識又梳理了一遍,有了這幾篇文章。記住,當人們都在大火猛炒的時候,你蒸的那鍋老粥就彌足珍貴了!本篇是...