|
@@ -1,9 +1,9 @@
|
|
|
package com.lovecoding.aop;
|
|
|
|
|
|
-import org.aspectj.lang.annotation.After;
|
|
|
-import org.aspectj.lang.annotation.AfterReturning;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.aspectj.lang.annotation.Before;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.Signature;
|
|
|
+import org.aspectj.lang.annotation.*;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@Aspect
|
|
@@ -15,10 +15,43 @@ public class CounterPorxy {
|
|
|
* Before 前置通知
|
|
|
* After 后置通知
|
|
|
* AfterReturning 返回通知
|
|
|
+ * Around 环绕通知
|
|
|
+ * AfterThrowing 异常通知
|
|
|
*/
|
|
|
@Before("execution(* com.lovecoding.aop.CountterImpl.*(..))")
|
|
|
- public void add(){
|
|
|
- System.out.println( "即将执行加法操作" );
|
|
|
+ public void add(JoinPoint joinPoint){
|
|
|
+ System.out.println( "前置通知" );
|
|
|
+ }
|
|
|
+
|
|
|
+ @After("execution(public int com.lovecoding.aop.CountterImpl.*(..))")
|
|
|
+ public void AfterAdd(JoinPoint joinPoint){
|
|
|
+ Signature signature = joinPoint.getSignature();
|
|
|
+ String name = signature.getName();
|
|
|
+ //System.out.println( "切入点 方法" + name );
|
|
|
+ System.out.println( "后置通知" );
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterReturning("execution(public int com.lovecoding.aop.CountterImpl.*(..))")
|
|
|
+ public void afterReturning(JoinPoint joinPoint){
|
|
|
+ System.out.println( "返回通知" );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Around("execution(public int com.lovecoding.aop.CountterImpl.*(..))")
|
|
|
+ public Object around( ProceedingJoinPoint joinPoint ){
|
|
|
+ try {
|
|
|
+ System.out.println( "环绕通知" );
|
|
|
+ return joinPoint.proceed(joinPoint.getArgs());
|
|
|
+ } catch (Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterThrowing("execution(public int com.lovecoding.aop.CountterImpl.*(..))")
|
|
|
+ public void AfterThrowing(JoinPoint joinPoint){
|
|
|
+ Signature signature = joinPoint.getSignature();
|
|
|
+ String name = signature.getName();
|
|
|
+ System.out.println( "方法 :" + name + "发生异常" );
|
|
|
}
|
|
|
|
|
|
}
|