日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于Execution 表达式

發(fā)布時(shí)間:2024/4/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于Execution 表达式 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)

modifiers-pattern:方法的操作權(quán)限

ret-type-pattern:返回值【必填】

declaring-type-pattern:方法所在的包

name-pattern:方法名【必填】

parm-pattern:參數(shù)名

throws-pattern:異常

目前SpringAOP 配置有兩種形式,這個(gè)小伙伴們應(yīng)該都非常清楚,我這里就不做過多贅述,如下Annotation 配置形式:

/*** Annotation版Aspect切面Bean*/ //聲明這是一個(gè)組件 @Component //聲明這是一個(gè)切面Bean @Aspect @Slf4j public class AnnotaionAspect {//配置切入點(diǎn),該方法無方法體,主要為方便同類中其他方法使用此處配置的切入點(diǎn)@Pointcut("execution(* com.leon.pattern.spring.aop.service..*(..))")public void aspect(){ }/** 配置前置通知,使用在方法aspect()上注冊的切入點(diǎn)* 同時(shí)接受JoinPoint切入點(diǎn)對(duì)象,可以沒有該參數(shù)*/@Before("aspect()")public void before(JoinPoint joinPoint){log.info("before通知 " + joinPoint);}//配置后置通知,使用在方法aspect()上注冊的切入點(diǎn)@After("aspect()")public void after(JoinPoint joinPoint){log.info("after通知 " + joinPoint);}//配置環(huán)繞通知,使用在方法aspect()上注冊的切入點(diǎn)@Around("aspect()")public void around(JoinPoint joinPoint){long start = System.currentTimeMillis();try {((ProceedingJoinPoint) joinPoint).proceed();long end = System.currentTimeMillis();log.info("around通知 " + joinPoint + "\tUse time : " + (end - start) + " ms!");} catch (Throwable e) {long end = System.currentTimeMillis();log.info("around通知 " + joinPoint + "\tUse time : " + (end - start) + " ms with exception : " + e.getMessage());}}//配置后置返回通知,使用在方法aspect()上注冊的切入點(diǎn)@AfterReturning("aspect()")public void afterReturn(JoinPoint joinPoint){log.info("afterReturn通知 " + joinPoint);}//配置拋出異常后通知,使用在方法aspect()上注冊的切入點(diǎn)@AfterThrowing(pointcut="aspect()", throwing="ex")public void afterThrow(JoinPoint joinPoint, Exception ex){log.info("afterThrow通知 " + joinPoint + "\t" + ex.getMessage());}}

Xml 配置形式:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd"><aop:aspectj-autoproxy proxy-target-class="true"/><bean id="xmlAspect" class="com.leon.pattern.spring.aop.aspect.XmlAspect"></bean><!-- AOP配置 --><aop:config><!-- 聲明一個(gè)切面,并注入切面Bean,相當(dāng)于@Aspect --><aop:aspect ref="xmlAspect"><!-- 配置一個(gè)切入點(diǎn),相當(dāng)于@Pointcut,用來切面規(guī)律一種語言 --><aop:pointcut expression="execution(* com.leon.pattern.spring.aop.service..*(..))" id="simplePointcut"/><!-- 配置通知,相當(dāng)于@Before、@After、@AfterReturn、@Around、@AfterThrowing --><aop:before pointcut-ref="simplePointcut" method="before"/><aop:after pointcut-ref="simplePointcut" method="after"/><aop:after-returning pointcut-ref="simplePointcut" method="afterReturn"/><aop:after-throwing pointcut-ref="simplePointcut" method="afterThrow" throwing="ex"/></aop:aspect></aop:config></beans>

?

總結(jié)

以上是生活随笔為你收集整理的关于Execution 表达式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。