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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

指定切面的优先级

發布時間:2024/4/13 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 指定切面的优先级 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

指定切面的優先級

在同一個連接點上應用不止一個切面時, 除非明確指定, 否則它們的優先級是不確定的.

切面的優先級可以通過實現 Ordered 接口或利用 @Order 注解指定.

實現 Ordered 接口, getOrder() 方法的返回值越小, 優先級越高.

若使用 @Order 注解, 序號出現在注解中

package com.learn.spring.aspectJ;import java.util.Arrays;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;/*** 日志切面*/ @Component //標識為組件 @Aspect //標識為切面 @Order(3) //指定切面的優先級. 值越小,優先級越高. 標注@Order的切面比不標注@Order切面的優先級高 public class LoggingAspect { /*** 前置通知: 在方法執行之前執行.* JoinPoint:連接點對象 包含了連接點相關的信息:方法名 方法的參數等....*///@Before("execution(public int com.learn.spring.aspectJ.ArithmeticCalculator.add(int,int))")//@Before("execution(public int com.learn.spring.aspectJ.ArithmeticCalculator.*(int,int))")//任意修飾符任意返回值 com.learn.spring.aspectJ包下的任意類的任意方法 任意參數//@Before("execution(* com.learn.spring.aspectJ.*.*(..))")@Before("suibian()")public void beforeMethod(JoinPoint joinPoint){//獲取方法名:String methodName = joinPoint.getSignature().getName();//獲取參數Object [] args = joinPoint.getArgs();System.out.println("The method "+methodName+" begins with "+ Arrays.asList(args));}} package com.learn.spring.aspectJ;import java.util.Arrays;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;@Component @Aspect @Order(2) public class ValidatorAspect {//@Before("execution(* com.learn.spring.aspectJ.*.*(..))")@Before("com.learn.spring.aspectJ.LoggingAspect.suibian()")public void beforeMethod(JoinPoint joinPoint){String methodName = joinPoint.getSignature().getName();Object [] args = joinPoint.getArgs();System.out.println("Validator===>The method "+methodName+" begins with" + Arrays.asList(args));} }

?

總結

以上是生活随笔為你收集整理的指定切面的优先级的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。