Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

统一异常处理器是aop吗 #485

Closed
wankaiyi opened this issue Apr 24, 2024 · 4 comments
Closed

统一异常处理器是aop吗 #485

wankaiyi opened this issue Apr 24, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@wankaiyi
Copy link

  • ruoyi-vue-pro 版本:v2.0.1
  • 操作系统:windows
  • 数据库:mysql

image

地址:https://github.com/YunaiV/ruoyi-vue-pro/blob/v2.0.1/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalResponseBodyHandler.java
今天再看源码的时候发现这段注释,我印象中统一异常处理器虽然叫advice,但是好像并不是aop,只是相当于在外层加了一些try-catch,不知道有没有记错

@liao-hao
Copy link

肯定是aop

@wankaiyi
Copy link
Author

肯定是aop

spring boot的aop现在都是用代理实现的,ControllerAdvice连代理都不是,为什么是aop呢

@liao-hao
Copy link

ai是个好东西:

在Spring框架中,AOP(面向切面编程)的实现通常是通过代理来完成的。但是,AOP的概念并不仅限于代理。AOP是一种编程范式,其核心思想是将那些与业务无关,但在多个地方被重复使用的代码(例如日志、事务管理、安全检查等),抽取出来,形成一个独立的模块,这个模块就是切面(Aspect)。

在Spring MVC中,@ControllerAdvice注解可以被视为一种AOP的应用,虽然它并不是通过代理来实现的。@ControllerAdvice注解可以定义全局的异常处理器,这个处理器可以捕获所有控制器抛出的异常。这就是一种横切关注点(Cross-cutting Concerns)的体现,也就是AOP的核心思想。

所以,即使@ControllerAdvice并不是通过代理来实现的,但是它的功能(全局异常处理)符合AOP的概念,因此我们可以将其视为AOP的一种应用。

@YunaiV
Copy link
Owner

YunaiV commented Apr 28, 2024

@YunaiV YunaiV self-assigned this Apr 28, 2024
@YunaiV YunaiV added the question Further information is requested label Apr 28, 2024
@YunaiV YunaiV closed this as completed Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants