public class XmlViewResolver extends AbstractCachingViewResolver implements Ordered, InitializingBean, DisposableBean
ViewResolver implementation that uses
bean definitions in a dedicated XML file for view definitions, specified by
resource location. The file will typically be located in the WEB-INF directory;
the default is "/WEB-INF/views.xml".
This ViewResolver does not support internationalization at the level
of its definition resources. Consider ResourceBundleViewResolver if you
need to apply different view resources per locale.
Note: This ViewResolver implements the Ordered interface
in order to allow for flexible participation in ViewResolver chaining.
For example, some special views could be defined via this ViewResolver
(giving it 0 as "order" value), while all remaining views could be resolved by
a UrlBasedViewResolver.
ResourceLoader.getResource(java.lang.String),
ResourceBundleViewResolver,
UrlBasedViewResolver| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_LOCATION
Default if no other location is supplied
|
DEFAULT_CACHE_LIMITloggerHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| Constructor and Description |
|---|
XmlViewResolver() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Pre-initialize the factory from the XML file.
|
void |
destroy()
Close the view bean factory on context shutdown.
|
protected Object |
getCacheKey(String viewName,
Locale locale)
This implementation returns just the view name,
as XmlViewResolver doesn't support localized resolution.
|
int |
getOrder()
Get the order value of this object.
|
protected BeanFactory |
initFactory()
Initialize the view bean factory from the XML file.
|
protected View |
loadView(String viewName,
Locale locale)
Subclasses must implement this method, building a View object
for the specified view.
|
void |
setLocation(Resource location)
Set the location of the XML file that defines the view beans.
|
void |
setOrder(int order)
Specify the order value for this ViewResolver bean.
|
clearCache, createView, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheLimit, setCacheUnresolvedgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextgetApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContextpublic static final String DEFAULT_LOCATION
public void setLocation(Resource location)
The default is "/WEB-INF/views.xml".
location - the location of the XML file.public void setOrder(int order)
The default value is Ordered.LOWEST_PRECEDENCE, meaning non-ordered.
Ordered.getOrder()public int getOrder()
OrderedHigher values are interpreted as lower priority. As a consequence,
the object with the lowest value has the highest priority (somewhat
analogous to Servlet load-on-startup values).
Same order values will result in arbitrary sort positions for the affected objects.
getOrder in interface OrderedOrdered.HIGHEST_PRECEDENCE,
Ordered.LOWEST_PRECEDENCEpublic void afterPropertiesSet()
throws BeansException
afterPropertiesSet in interface InitializingBeanBeansExceptionprotected Object getCacheKey(String viewName, Locale locale)
getCacheKey in class AbstractCachingViewResolverprotected View loadView(String viewName, Locale locale) throws BeansException
AbstractCachingViewResolverSubclasses are not forced to support internationalization: A subclass that does not may simply ignore the locale parameter.
loadView in class AbstractCachingViewResolverviewName - the name of the view to retrievelocale - the Locale to retrieve the view fornull if not found
(optional, to allow for ViewResolver chaining)BeansExceptionAbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)protected BeanFactory initFactory() throws BeansException
BeansException - in case of initialization errorspublic void destroy()
throws BeansException
destroy in interface DisposableBeanBeansException