aop 中joinpoint的使用方法

一.簡述下joinpoint在不同情況下的不同:

1.在around中可以用,此時可以執行被包裹的代碼,可以根據情況來判斷是否執行被包裹的代碼,以實現控制的作用。

  1. public void around(ProceedingJoinPoint joinpoint) {  
  2.     joinpoint.proceed();  
  3. }  

2.別的用,常用於做記錄之用,不能控制被包裹的代碼是否執行。

  1. public void before(JoinPoint joinpoint) {  
  2.   
  3. }  

主要區別:在於是否能控制被包裹的代碼。


二.joinpoint如何查看類調用情況:

  1. joinpoint.getArgs();//輸入的參數列表  
  2.   
  3. joinpoint.getTarget().getClass().getName();//類全路徑  
  4.   
  5. joinpoint.getSignature().getDeclaringTypeName();//接口全路徑  
  6.           
  7. joinpoint.getSignature().getName();//調用的方法  


三.什麼是Signature

public interface Signature


Represents the signature at a join point. This interface parallels java.lang.reflect.Member.


This interface is typically used for tracing or logging applications to obtain reflective information about the join point, i.e. using the j2se 1.4java.util.logging API


 aspect Logging {
Logger logger = Logger.getLogger("MethodEntries");
 before(): within(com.bigboxco..*) &amp;&amp; execution(public * *(..)) {</br>
     Signature sig = thisJoinPoint.getSignature();</br>
     logger.entering(sig.getDeclaringType().getName(),</br>
                     sig.getName());</br>
 }</br>

}


api網址:http://www.eclipse.org/aspectj/doc/next/runtime-api/

原文地址:https://www.cnblogs.com/jpfss/p/8126634.html