spring 注解实现AOP

xiaoxiao2021-02-28  93

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 @Aspect public 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{ } }
转载请注明原文地址: https://www.6miu.com/read-19244.html

最新回复(0)