简体   繁体   中英

Is customizing DispatcherServlet in Spring MVC a common practice?

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.

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.

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.

Here's my suggestion where I am thinking that extending the dispatcher servlet would be 'a' solution.

  1. separate validation, conversion from controller (for several good reasons)
  2. make the controller just a delegator to service layer.
  3. build/populate the domain/request object fully 'before' it reaches the controller.

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.

例如,我从来没有找到扩展DispatcherServlet的理由。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM