spring 注解实现AOP

来源:互联网 发布:java异常处理 编辑:程序博客网 时间:2024/05/02 01:00
import java.lang.reflect.Method;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.annotation.Resource;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.aspectj.lang.JoinPoint;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.reflect.MethodSignature;import org.springframework.stereotype.Component;/** * handler调用前通用方法 */@Component@Aspectpublic class CommonInterceptor {        /*         *前置通知 对com.foo.external.oa.service.impl 目录下execute()方法织入         */@Before("execution(* com.foo.external.oa.service.impl.*.execute(..))")    public void beforeMethod(JoinPoint joinPoint)  throws Throwable {    }    /*     *环绕通知 对com.foo.external.oa.service.impl 目录下的execute织入     */     @AfterThrowing(value="execution(* com.foo.external.oa.service.impl.*.execute(..))", throwing="ex")     public void afterThrowing(JoinPoint joinPoint, Exception ex) throws Throwable{     }}
0 0