I followed the Spring Learning Note (--AOP) to return notification before
/**
* Return Notification: The method is called after normal execution and, if there is an exception, the return value
of the * can access to the method is not invoked *
@param joinpoint
* @param result method
*
/@AfterReturning (value= "Execution (* com.zj.asceptj.*.* (..))", returning= "result") public
Void Afterreturning (joinpoint joinpoint,object result) {
//method name
String methodname = Joinpoint.getsignature (). GetName ();
System.out.println ("Method" +methodname+ "End:" +result);
}
Exception Notification
/**
* Exception notification:
* You can specify which exceptions occur when the method is abnormal: how to specify. specified by an entry parameter, such as:
* If the join parameter is Nullpointexception ex, the
* @param joinpoint
* @param ex
* * is only performed when a null pointer exception occurs Afterthrowing (value= "Execution (* com.zj.asceptj.*.* (..))", throwing= "ex") public
void Afterthrowing (joinpoint Joinpoint,exception ex) {
//method name
String methodname = Joinpoint.getsignature (). GetName ();
System.out.println ("method" +methodname+ "occurs:" +ex);
}
Surround NotificationSurround notification is similar to the whole process of dynamic agents, you can use surround notification to implement the forward notification, post notification, return notification, exception notification function, very powerful, but not commonly used on dynamic proxies, see Spring Learning Notes (--AOP) basics
/** * Surround notification needs to carry a proceedingjoinpoint type of parameter * wrapping notification is similar to the whole process of dynamic proxies: Proceedingjoinpoint This type of parameter Number can determine whether to execute the target method * and the surround notification must have a return value, which is the return value of the target method * @param PJD/@Around ("Execution (* com.zj.asceptj.*.* (..))
") public Object Around (Proceedingjoinpoint pjd) {object result = NULL;
String methodname = Pjd.getsignature (). GetName (); try {//forward notification System.out.println (' method: ' +methodname+ ' begins with ' +arrays.aslist (Pjd.getargs ())
;
Execute target method result = Pjd.proceed ();
Returns the notification System.out.println ("method:" +methodname+ "End With" +result);
catch (Throwable e) {//Exception notification System.out.println ("method:" +methodname+ "occurs exception" +e);
//Post Notification System.out.println ("method ends");
return result; }