File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Interceptor inside applicationcontext.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Interceptor inside applicationcontext.xml?" Watch "Interceptor inside applicationcontext.xml?" New topic
Author

Interceptor inside applicationcontext.xml?

Kelly Powell
Ranch Hand

Joined: Oct 29, 2010
Posts: 56
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kelly Powell
Ranch Hand

Joined: Oct 29, 2010
Posts: 56
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Oct 29, 2010
Posts: 56
I see. So the code below is not a Spring interceptor?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Oct 29, 2010
Posts: 56
Sorry, I almost forgot about this thread. I understand it now. Thanks, Mark!
 
jQuery in Action, 2nd edition
 
subject: Interceptor inside applicationcontext.xml?