调整目录结构

master
linlei 2024-04-26 16:46:53 +08:00
parent 0ce87edf53
commit db9566fc99
3 changed files with 24 additions and 39 deletions

View File

@ -198,20 +198,21 @@
+ Spring AOP + Spring AOP
- [JDK动态代理](spring-aop/spring-aop-jdkProxy/README.md):接口实现,动态生成代理类,处理方法调用,统一横切关注点。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [JDK动态代理](spring-aop/spring-aop-jdkProxy/README.md):接口实现,动态生成代理类,处理方法调用,统一横切关注点。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Cglib动态代理](spring-aop/spring-aop-cglibProxy/README.md):基于字节码生成的库,无需接口,可拦截类方法并进行增强。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [Cglib动态代理](spring-aop/spring-aop-cglibProxy/README.md):基于字节码生成的库,无需接口,可拦截类方法并进行增强。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [AopProxy](spring-aop/spring-aop-aopProxy/README.md)创建和管理AOP代理对象。<img src="https://img.shields.io/badge/Level-%E5%9B%B0%E9%9A%BE-%23FF3030"></img>
- [AopProxyFactory](spring-aop/spring-aop-aopProxyFactory/README.md)创建AOP代理工厂支持JDK和CGLIB。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [ProxyFactory](spring-aop/spring-aop-proxyFactory/README.md):一种便捷的方式来创建代理对象。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [ClassFilter](spring-aop/spring-aop-classFilter/README.md):确定类是否匹配拦截条件。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [ClassFilter](spring-aop/spring-aop-classFilter/README.md):确定类是否匹配拦截条件。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [MethodMatcher](spring-aop/spring-aop-methodMatcher/README.md):确定方法是否匹配拦截条件。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [MethodMatcher](spring-aop/spring-aop-methodMatcher/README.md):确定方法是否匹配拦截条件。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Pointcut](spring-aop/spring-aop-pointcut/README.md):定义切入点,匹配被拦截的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [Pointcut](spring-aop/spring-aop-pointcut/README.md):定义切入点,匹配被拦截的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Advice]()AOP中定义各种通知类型行为的核心接口。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [MethodInterceptor](spring-aop/spring-aop-advice-methodInterceptor/README.md):拦截方法执行,允许在前后添加额外逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [MethodInterceptor](spring-aop/spring-aop-advice-methodInterceptor/README.md):拦截方法执行,允许在前后添加额外逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [MethodBeforeAdvice](spring-aop/spring-aop-advice-methodBeforeAdvice/README.md):允许在方法调用之前插入自定义逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [MethodBeforeAdvice](spring-aop/spring-aop-advice-methodBeforeAdvice/README.md):允许在方法调用之前插入自定义逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [AfterReturningAdvice](spring-aop/spring-aop-advice-afterReturningAdvice/README.md):允许在方法调用之后插入自定义逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [AfterReturningAdvice](spring-aop/spring-aop-advice-afterReturningAdvice/README.md):允许在方法调用之后插入自定义逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ThrowsAdvice](spring-aop/spring-aop-advice-throwsAdvice/README.md):异常通知,捕获方法抛出的异常,执行额外逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [ThrowsAdvice](spring-aop/spring-aop-advice-throwsAdvice/README.md):异常通知,捕获方法抛出的异常,执行额外逻辑。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [IntroductionInterceptor](spring-aop/spring-aop-advice-introductionInterceptor/README.md):动态地向目标对象引入新的功能或属性。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [IntroductionInterceptor](spring-aop/spring-aop-advice-introductionInterceptor/README.md):动态地向目标对象引入新的功能或属性。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [Advised](spring-aop/spring-aop-advised/README.md)配置AOP代理的通知、通知器、目标等。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [ProxyFactory](spring-aop/spring-aop-proxyFactory/README.md):一种便捷的方式来创建代理对象。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [AopProxy](spring-aop/spring-aop-aopProxy/README.md)创建和管理AOP代理对象。<img src="https://img.shields.io/badge/Level-%E5%9B%B0%E9%9A%BE-%23FF3030"></img>
- [AopProxyFactory](spring-aop/spring-aop-aopProxyFactory/README.md)创建AOP代理工厂支持JDK和CGLIB。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Advisor](spring-aop/spring-aop-advisor/README.md):用于将通知和切点结合,实现切面编程的横切关注点。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [Advisor](spring-aop/spring-aop-advisor/README.md):用于将通知和切点结合,实现切面编程的横切关注点。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [AdvisorAdapter](spring-aop/spring-aop-advisorAdapter/README.md):适配不同类型通知到拦截器链。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [AdvisorAdapter](spring-aop/spring-aop-advisorAdapter/README.md):适配不同类型通知到拦截器链。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [Advised](spring-aop/spring-aop-advised/README.md)配置AOP代理的通知、通知器、目标等。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [TargetSource](spring-aop/spring-aop-targetSource/README.md)管理AOP代理对象的获取与释放。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [TargetSource](spring-aop/spring-aop-targetSource/README.md)管理AOP代理对象的获取与释放。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [TargetSourceCreator](spring-aop/spring-aop-targetSourceCreator/README.md):创建特殊的目标源,定制代理对象的创建和管理。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [TargetSourceCreator](spring-aop/spring-aop-targetSourceCreator/README.md):创建特殊的目标源,定制代理对象的创建和管理。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [@EnableAspectJAutoProxy](spring-aop/spring-aop-enableAspectJAutoProxy/README.md)启用AspectJ切面自动代理。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [@EnableAspectJAutoProxy](spring-aop/spring-aop-enableAspectJAutoProxy/README.md)启用AspectJ切面自动代理。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>

View File

@ -23,19 +23,10 @@
1. **组合切点和通知** 1. **组合切点和通知**
+ Advisor接口允许将切点Pointcut和通知Advice组合在一起。切点确定何时应该应用通知而通知定义了在连接点处执行的代码。 + Advisor接口允许将切点Pointcut和通知Advice组合在一起。切点确定何时应该应用通知而通知定义了在连接点处执行的代码。
2. **定义横切逻辑**
+ 通过Advisor接口及其实现类可以定义在应用程序中何时、何地以及如何应用横切关注点cross-cutting concerns如日志记录、事务管理、安全性等。
3. **提供AOP配置的抽象** 3. **提供AOP配置的抽象**
+ Advisor接口是AOP配置的一种抽象它使得可以通过编程方式或声明式的方式定义切面并将它们应用到目标对象上。 + Advisor接口是AOP配置的一种抽象它使得可以通过编程方式或声明式的方式定义切面并将它们应用到目标对象上。
4. **实现面向切面编程**
+ Advisor接口是面向切面编程AOP的核心组件之一它允许我们在不改变业务逻辑的情况下通过切面来管理横切关注点从而提高代码的模块化和可维护性。
### 四、接口源码 ### 四、接口源码
`Advisor`接口是Spring框架中的一个基础接口用于持有AOP通知在连接点执行的操作和确定通知适用性的过滤器例如切点。该接口定义了获取通知部分的方法`getAdvice()`,以及确定通知是否与特定实例相关联的方法`isPerInstance()`。同时,该接口还提供了一个常量`EMPTY_ADVICE`用作当未配置适当通知时的占位符。在Spring AOP中Advisor接口允许支持不同类型的通知例如拦截器、前置通知、异常通知等并且并非所有通知都需要使用拦截来实现。 `Advisor`接口是Spring框架中的一个基础接口用于持有AOP通知在连接点执行的操作和确定通知适用性的过滤器例如切点。该接口定义了获取通知部分的方法`getAdvice()`,以及确定通知是否与特定实例相关联的方法`isPerInstance()`。同时,该接口还提供了一个常量`EMPTY_ADVICE`用作当未配置适当通知时的占位符。在Spring AOP中Advisor接口允许支持不同类型的通知例如拦截器、前置通知、异常通知等并且并非所有通知都需要使用拦截来实现。
@ -207,28 +198,16 @@ Executing bar method
1. **切点定义错误** 1. **切点定义错误**
+ 定义切点时可能会出现错误,导致切面未能正确地匹配到预期的连接点。这可能是因为切点表达式错误,或者切点逻辑与实际场景不匹配 + 切点定义不准确或逻辑错误,导致切面无法正确地匹配到预期的连接点
2. **通知应用顺序错误** 2. **通知逻辑错误**
+ 当存在多个Advisor时通知的应用顺序可能会影响最终的切面逻辑。如果通知的应用顺序不正确可能会导致意外的行为或不一致的结果 + 通知逻辑的实现可能存在错误,导致切面的行为与预期不符
3. **切面匹配范围不正确** 3. **切面顺序问题**
+ 切面的匹配范围可能过于宽泛或过于狭窄,导致通知被应用于不希望被影响的连接点,或者未能影响到应该被影响的连接点 + 当存在多个Advisor时通知的应用顺序可能会影响最终的切面逻辑需要正确地管理切面的顺序
4. **性能问题** 4. **切面匹配范围问题**
+ 使用过多或过于复杂的切面可能会影响应用程序的性能。因此,在设计切面时需要考虑性能问题,并尽量减少切面的数量和复杂度。 + 切面匹配范围过于宽泛或过于狭窄,导致切面的逻辑影响到不应该被影响的连接点,或者未能影响到应该被影响的连接点。
5. **代理问题**
+ 如果代理配置不正确,可能会导致切面无法正确应用。例如,如果代理对象的类型与切面匹配范围不一致,或者代理对象不符合切面的预期行为,都可能导致切面无法正确工作。
6. **异常处理问题**
+ 切面中的异常处理可能会影响应用程序的正常运行。如果异常处理不正确,可能会导致应用程序无法正确处理异常情况,从而影响用户体验。
7. **与其他切面冲突**
+ 如果存在多个切面,并且它们的匹配范围有重叠,可能会导致切面之间的冲突。例如,两个切面都匹配同一个连接点,并且它们的通知行为相互矛盾,可能会导致意料之外的结果。

View File

@ -2,13 +2,13 @@ package com.xcs.spring;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor; import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
/** /**
* Advisor * Advisor
*/ */
public class MyCustomAdvisor extends AbstractPointcutAdvisor { public class MyCustomAdvisor implements PointcutAdvisor {
/** /**
* *
@ -29,4 +29,9 @@ public class MyCustomAdvisor extends AbstractPointcutAdvisor {
public Advice getAdvice() { public Advice getAdvice() {
return advice; return advice;
} }
@Override
public boolean isPerInstance() {
return true;
}
} }