AspectJ的兩種實現

2021-10-03 01:32:35 字數 2059 閱讀 6174

① 基於xml方式實現:

public

class

myaspect

public

void

myafterretruning

(joinpoint joinpoint)

}

public

inte***ce

userservice

1. 建立實體類 --

>

"userserviceid"

class

="com.itt.c_aspectj_xml.userserviceimpl"

>

<

/bean>

2. 建立切面類--

>

"aspectid"

class

="com.itt.c_aspectj_xml.myaspect"

>

<

/bean>

3. 建立**類--

>

將切面類宣告「切面」, 獲得通知

切入點,expression:為切入點表示式

"" pointcut-ref=

"">

前置通知,method為通知的方法,pointcut-ref為切入點的引用

-->

"aspectid"

>

"myaspectid" expression=

"execution(* com.itt.c_aspectj_xml.userserviceimpl.*(..))"

/>

"mybefore" pointcut-ref=

"myaspectid"

>

<

/aop:before>

"myafterretruning" pointcut-ref=

"myaspectid"

>

<

/aop:after>

<

/aop:aspect>

<

/aop:config>

②基於註解方式:

//切面類

@component

@aspect

public

class

myaspect

@before

(value =

"mypoint()"

)public

void

mybefore

(joinpoint joinpoint)

@after

(value =

"mypoint()"

)public

void

myafterretruning

(joinpoint joinpoint)

}

@service

("userserviceid"

)//指定生成的bean的id

public

class

userserviceimpl

implements

userservice

@override

public string updateuser()

@override

public

void

deleteuser()

}

<

!--掃瞄所有的註解--

>

package

="com.itt.c_aspectj_xml"

>

<

/context:component-scan>

<

!--確定aop註解生效--

>

<

/aop:aspectj-autoproxy>

棧的兩種實現

順序表實現棧 include include 順序表實現棧 define test head printf n s n function define default sz 5 typedef char datatype typedef struct seqstack seqstack 棧的初始化 ...

棧的兩種實現

棧的基本實現 include stdafx.h include include define maxsize 64 using namespace std 基於陣列實現的棧 class stack 預設建構函式 int push int data 元素入棧 int pop 元素出棧 bool ise...

mysleep 的兩種實現

mysleep 的兩種實現 一 include include include void myhandler int sig 控制代碼函式什麼也不做 int mysleep int timeout int main return 0 二 避免競態條件的mysleep include include ...