views:

992

answers:

5

Hi,

I am new to Spring MVC. But I had certain experience in working with Struts 1.x. I would like to know if it is a common practice to customize DispatcherServlet while working with Spring MVC, like people sometimes customize ActionServlet or RequestProcessor in Struts 1.x?

Or let's extend the question a little bit. Where are the entry points for a veteran Spring MVC programmer to customize the MVC framework?

Thank you.

+1  A: 

Why would you want specialize org.springframework.web.servlet.DispatcherServlet?

Any request pre-processing can/should be achieved with a javax.servlet.Filter and the rest is down to the implementation of org.springframework.web.servlet.mvc.Controller.

Alternatively see adatapost's answer, which refers to configuration of the org.springframework.web.servlet.DispatcherServlet via the web.xml file.

Nick Holt
I ask this question so that I can understand this framework better, and to see what this way can serve. :)
Winston Chen
+2  A: 

Definitely it is a good practice. Spring Framework - Web MVC framework

SUMMARY: You can customize Spring's DispatcherServlet by adding context parameters .... especially handy when you have a lot of common functionality in one controller.

adatapost
Thanks, it's helpful.
Winston Chen
+2  A: 

DispatcherServlet, like most of the Spring API, is very much designed for extension. Indeed, if you find a part of it that's not ammenable to subclassing, file an issue on their JIRA and they'll likely fix it for you (I've done that on a number of occasions).

Having said that, the vast majority of functionality can be achieved via configuration of DispatcherServlet rather than extension of it.

skaffman
You are right. I cannot even name a single thing that cannot be achieved by it's current implementation. Thank you for your advise. I will file a issue if I find the necessity.
Winston Chen
+1  A: 

I, for one, have never found a reason to extend DispatcherServlet.

duffymo
This is good to know ;)
Winston Chen