Class XmlViewResolver
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.view.AbstractCachingViewResolver
- org.springframework.web.servlet.view.XmlViewResolver
- All Implemented Interfaces:
Aware,DisposableBean,InitializingBean,ApplicationContextAware,Ordered,ServletContextAware,ViewResolver
public class XmlViewResolver extends AbstractCachingViewResolver implements Ordered, InitializingBean, DisposableBean
AViewResolverimplementation 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
ViewResolverdoes not support internationalization at the level of its definition resources. ConsiderResourceBundleViewResolverif you need to apply different view resources per locale.Note: This
ViewResolverimplements theOrderedinterface in order to allow for flexible participation inViewResolverchaining. For example, some special views could be defined via thisViewResolver(giving it 0 as "order" value), while all remaining views could be resolved by aUrlBasedViewResolver.- Since:
- 18.06.2003
- Author:
- Juergen Hoeller
- See Also:
ResourceLoader.getResource(java.lang.String),ResourceBundleViewResolver,UrlBasedViewResolver
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_LOCATIONDefault if no other location is suppliedFields inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
DEFAULT_CACHE_LIMIT
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description XmlViewResolver()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Pre-initialize the factory from the XML file.voiddestroy()Close the view bean factory on context shutdown.protected ObjectgetCacheKey(String viewName, Locale locale)This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.intgetOrder()Get the order value of this object.protected BeanFactoryinitFactory()Initialize the view bean factory from the XML file.protected ViewloadView(String viewName, Locale locale)Subclasses must implement this method, building a View object for the specified view.voidsetLocation(Resource location)Set the location of the XML file that defines the view beans.voidsetOrder(int order)Specify the order value for this ViewResolver bean.Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
clearCache, createView, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheLimit, setCacheUnresolved
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
Field Detail
DEFAULT_LOCATION
public static final String DEFAULT_LOCATION
Default if no other location is supplied- See Also:
- Constant Field Values
Constructor Detail
XmlViewResolver
public XmlViewResolver()
Method Detail
setLocation
public void setLocation(Resource location)
Set the location of the XML file that defines the view beans.The default is "/WEB-INF/views.xml".
- Parameters:
location- the location of the XML file.
setOrder
public void setOrder(int order)
Specify the order value for this ViewResolver bean.The default value is
Ordered.LOWEST_PRECEDENCE, meaning non-ordered.- See Also:
Ordered.getOrder()
getOrder
public int getOrder()
Description copied from interface:OrderedGet the order value of this object.Higher 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-startupvalues).Same order values will result in arbitrary sort positions for the affected objects.
- Specified by:
getOrderin interfaceOrdered- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
afterPropertiesSet
public void afterPropertiesSet() throws BeansException
Pre-initialize the factory from the XML file. Only effective if caching is enabled.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
BeansException
getCacheKey
protected Object getCacheKey(String viewName, Locale locale)
This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.- Overrides:
getCacheKeyin classAbstractCachingViewResolver
loadView
protected View loadView(String viewName, Locale locale) throws BeansException
Description copied from class:AbstractCachingViewResolverSubclasses must implement this method, building a View object for the specified view. The returned View objects will be cached by this ViewResolver base class.Subclasses are not forced to support internationalization: A subclass that does not may simply ignore the locale parameter.
- Specified by:
loadViewin classAbstractCachingViewResolver- Parameters:
viewName- the name of the view to retrievelocale- the Locale to retrieve the view for- Returns:
- the View instance, or
nullif not found (optional, to allow for ViewResolver chaining) - Throws:
BeansException- See Also:
AbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)
initFactory
protected BeanFactory initFactory() throws BeansException
Initialize the view bean factory from the XML file. Synchronized because of access by parallel threads.- Throws:
BeansException- in case of initialization errors
destroy
public void destroy() throws BeansException
Close the view bean factory on context shutdown.- Specified by:
destroyin interfaceDisposableBean- Throws:
BeansException