Interceptors vs Aspects in Spring?
Asked Answered
G

1

35

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?

Garrard answered 30/8, 2010 at 11:41 Comment(0)
O
68

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.

Orthopterous answered 30/8, 2010 at 13:38 Comment(2)
you are totally getting the point, i understand now that interceptors as term will be related to web requests, and that isn't what i need, i need the method interceptors indeed, and after reading through documents, i think it's complex some way, so is there a simpler way to perform itGarrard
Excellent answer. it is very useful while develop this concepts in the projectPlane

© 2022 - 2024 — McMap. All rights reserved.