春季拦截器与方面? [英] Interceptors vs Aspects in Spring?

查看:107
本文介绍了春季拦截器与方面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Spring中使用拦截器.我想在某些方法上实现拦截器,以在调用这些方法时处理特定的逻辑.我还希望除了使用Web框架之外,更倾向于使用Spring作为后端,而没有任何标题.

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.

搜索后,我认为春季方法被称为Aspects,能否请您提及最佳做法?

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

推荐答案

在Spring中,有两种不同的构造称为拦截器".

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"

然后您具有方法拦截器,它们是 Spring AOP 框架.这些是比Handler Interceptor更通用的机制,但也可能更复杂.在AOP术语中,此类拦截器提供了一种对您正在谈论的方面"进行编码的方法.

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方面是一个复杂的主题.如果您有兴趣,建议您略过

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.

这篇关于春季拦截器与方面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆