Spring MVC provides a convenient way to add your custom mapping handler, view resolver,locale resolution,theme resolution and request handlers. This convenience is achieved by strategy pattern. This feature makes Spring MVC different from other web framework because it is not request-oriented and driven web framework.
In the package of Spring MVC, one file named DispatcherServlet.properties is included in the jar packages. In that property file, all kinds of default implementations are defined. In the normal process of Spring MVC, it usually loads your custom implementations at first. If your custom ones are not found, it will turn to DispatcherServlet.properties for help. That is to say, all of the default implementations are the last resorts.
org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver
org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver,\
org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,\
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver
org.springframework.web.servlet.FlashMapManager=org.springframework.web.servlet.support.SessionFlashMapManager

本文介绍了SpringMVC中如何通过策略模式实现自定义映射处理器、视图解析器等功能。SpringMVC提供了便捷的方式让开发者可以轻松地添加自己的实现,并详细列举了默认配置文件DispatcherServlet.properties中的各项默认实现。
1943

被折叠的 条评论
为什么被折叠?



