Spring 中的拦截器与方面?

发布于 2024-09-16 05:36:16 字数 156 浏览 2 评论 0原文

我正在尝试在 Spring 中使用拦截器。我想在某些方法上实现拦截器,以在调用这些方法时处理特定逻辑。我还想不使用 Web 框架,因为我倾向于使用 Spring 作为后端,而不使用任何标头。

经过搜索,我认为 spring 方法称为 Aspects,您能否提及执行此操作的最佳实践?

I am trying to use interceptors in Spring. I want to implement an interceptor on some methods to handle specific logic when these methods are called. I also want to be apart from using web framework, as am tending to use Spring as back end, without any headers.

After searching, I think spring approach is called Aspects, could you please mention best practice to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜警司 2024-09-23 05:36:16

在 Spring 中,有两种不同的构造被称为“拦截器”。

首先,有 HandlerInterceptors,它是 Spring MVC 框架的一部分,允许您向 Web 请求添加拦截器逻辑。我怀疑这就是你说“拦截器”时的意思

然后你有方法拦截器,它是 Spring AOP 框架。这些是比处理程序拦截器更通用的机制,但也可能更复杂。在 AOP 术语中,此类拦截器提供了一种对您正在讨论的“方面”进行编码的方法。 AOP

方面是一个复杂的主题。如果您有兴趣,我建议您浏览一下 中的内容Spring AOP 手册并了解术语以及它能为您做什么和不能为您做什么。

In Spring there are two different constructs that get called "interceptors".

First, there are Handler Interceptors, which are part of the Spring MVC framework, and allow you to add interceptor logic to web requests. I suspect this is what you meant when you said "interceptors"

Then you have Method Interceptors, which are part of the Spring AOP framework. These are much more general mechanism than Handler Interceptors, but also potentially more complex. In AOP terminology, such interceptors provide a means of coding the "aspects" you're talking about. The

AOP aspects are a complex subject. If you're interested, I suggest that you skim over the stuff in the Spring AOP manual and get a feel for the terminology, and what it can and can't do for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文