Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interceptor inside applicationcontext.xml?

 
Kelly Powell
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that this might be a silly question but can you please explain what are interceptors and how does it work in Spring? And why are they declared inside applicationcontext.xml. Plus how are they related to auditing? Thank you!
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to first clarify what type of Interceptor you mean. There are many types of interceptors out there and not all of them are from Spring or Spring specific. And we need to clarify "Spring".

I am going to make some assumptions here. 1) You are using Spring MVC, which is the Web Layer technology that Spring can provide, and works in the Spring Framework/Container. Spring MVC does not necessarily have to be used to use Spring, you could just use the Spring Framework/Container.

An Interceptor in Spring MVC is just like a Servlet Filter. You can intercept calls to a Controller method, and have code in the interceptor run before and after your code in your controller to run.

You can define Interceptors for Spring MVC in your configuration file.

Again, what do you mean by auditing? auditing what? Is this just logging? And Interceptors can be used for auditing, but you define that yourself, not Spring. Meaning you implement your own auditing by creating your own Interceptor, or by other means.

Mark
 
Kelly Powell
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for replying!

Yes, the web application that I'm currently reviewing is using Spring MVC. I think the interceptor it uses is also from Spring since it (the java class) implemented a Spring interface.

By auditing, I am referring to the act of recording all the transaction details. I think it's the same as logging? Or am I wrong?

Again, thanks for the clarification! I understand now that interceptor is just like a listener.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because your Interceptor class implements a Spring interface or class, doesn't necessarily mean it is a class that Spring provides. It can still be one of your own classes.

For instance, this is my class


It implements a Spring interface, but I wrote it, it does not come from Spring. ;)

Mark
 
Kelly Powell
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. So the code below is not a Spring interceptor?
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the package statement at the top. Does it have org.springsource.something as the package structure. If so, then Spring created that class, if not someone else did.

But it does implement a Spring interface.

Again, just like in my example I have a non Spring class that is implementing a Spring class.

Do you see the distinction I am making? Another example

public class Mark implements Serializable {}

I implement a Java SDK interface called Serializable, but it doesn't make Mark a Java SDK class.

Mark
 
Kelly Powell
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I almost forgot about this thread. I understand it now. Thanks, Mark!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic