# custom-aop **Repository Path**: Zany_JMaker/custom-aop ## Basic Information - **Project Name**: custom-aop - **Description**: 这是一款基于spring-aop的自定义的AOP组件,可以简单的使用注解和实现接口来实现AOP切面操作 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-06-06 - **Last Updated**: 2024-06-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Custom-Aop ## 简介 这是一款基于spring-aop的自定义的AOP组件,可以简单的使用注解和实现接口来实现AOP切面操作 ## 项目架构 项目使用JDK8\ 项目引入以下组件 ```$xslt org.springframework spring-aop 5.2.25.RELEASE org.springframework spring-context 5.2.25.RELEASE org.aspectj aspectjweaver 1.9.1 ``` ## 使用说明 ### 项目主要包含: 一个AOP类: com.zany.aop.CustomAroundAop \ 一个注解类: com.zany.aop.annotation.CustomAround \ 以及 com.zany.aop.support 包下5个接口类,类图如下 ![接口类图](./类图.jpg) 其中: 1. PreferenceInterface 接口为优先级接口,用于多个AOP时,设置AOP执行优先级(preference() 返回值越小,优先级越高),其他4个接口均继承该接口; 2. BeforeInterface,AfterInterface,ThrowableInterface,AroundInterface 接口分别为Before,After,Throwable,Around的实现接口; 3. AroundInterface 接口继承BeforeInterface,AfterInterface,ThrowableInterface三个接口,并且由于AroundInterface可以同时存在Before,After,Throwable三种AOP, 所以AroundInterface既可以统一配置优先级,也可以单独配置三种AOP的优先级,且每种AOP取两种优先级中最小的值(即:最高优先级生效)作为优先级。 ### 使用例子 ```$xslt /** *

* 测试 Around增强 *

* * @author Zany 2024/06/06 */ @Slf4j @Component public class TestAround implements AroundInterface { @Override public Object[] before(JoinPoint point, Object[] args) { log.info("before aop"); return args; } @Override public Object after(JoinPoint point, Object[] args, Object result) { log.info("after aop"); return result; } @Override public void throwable(JoinPoint point, Object[] args, Object result, Throwable t) { log.error("throwable aop", t); } @Override int beforePreference(){return 1;} @Override int afterPreference(){return 5;} // 此时实际生效的throwable优先级为8 @Override int throwablePreference(){return 10;} @Override int preference() {return 8;} ```