Types of ViewResolver
ViewResolveris a strategy interface within the framework. In order to get a better handle on how
view resolution is applied through this interface, we’ll introduce some of the abstract and con-
crete implementations. Figure 7-5 details the relationships between various ViewResolverclasses.
Figure 7-5.ViewResolver hierarchy
That’s a lot of ViewResolvers, so what do they all do? Let’s briefly examine some of the
more important ones.
- BeanNameViewResolveris a simple implementation of the interface that is useful
in smaller applications. It attempts to resolve views as beans defined in the
ApplicationContext, so the name of the view is the idof a bean. This resolver needs
no additional configuration, but it has the disadvantage of requiring view beans to be
defined in the ApplicationContextfile. - AbstractCachingViewResolveris the superclass to all resolvers that wish to cache their
view objects. Creating a Viewcan be an expensive operation, so this is a useful piece of
common functionality. - XmlViewResolvercreates views based on an XML definition file. This file (/WEB-INF/
views.xmlby default) uses the Spring Beans DTD, which has the advantage of making
view definitions both familiar and able to use the full power of Spring’s bean factories.
ViewResolver
+ resolveViewname(viewName : string, locale : Locale) : View
AbstractCachingViewResolver BeanNameViewResolver
ResourceBundleViewResolver XmlViewResolver UrlBasedViewResolver
InternalResourceViewResolver AbstractTemplateViewResolver
VelocityViewResolver FreeMarkerViewResolver
210 CHAPTER 7 ■THE VIEW LAYER