Top Description Fields Constructors Methods
org.springframework.web.servlet.view

public Class XmlViewResolver

extends AbstractCachingViewResolver
implements Ordered, InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered
Annotations
@Deprecated
Imports
java.util.Locale, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .DisposableBean, .InitializingBean, .NoSuchBeanDefinitionException, org.springframework.beans.factory.xml.ResourceEntityResolver, .XmlBeanDefinitionReader, org.springframework.context.ApplicationContext, .ConfigurableApplicationContext, org.springframework.core.Ordered, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.web.servlet.View

Deprecated

as of 5.3, in favor of Spring's common view resolver variants and/or custom resolver implementations

A org.springframework.web.servlet.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.

Author
Juergen Hoeller
Since
18.06.2003
See Also
org.springframework.context.ApplicationContext#getResource, UrlBasedViewResolver, BeanNameViewResolver

Field Summary

Modifier and TypeField and Description
private ConfigurableApplicationContext
public static final String
DEFAULT_LOCATION

Default if no other location is supplied.

private Resource
private int
Inherited from org.springframework.web.servlet.view.AbstractCachingViewResolver:
DEFAULT_CACHE_LIMIT

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Pre-initialize the factory from the XML file.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Close the view bean factory on context shutdown.

protected Object
getCacheKey(String viewName, Locale locale)

Overrides org.springframework.web.servlet.view.AbstractCachingViewResolver.getCacheKey.

This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.

public int
getOrder()

Implements org.springframework.core.Ordered.getOrder.

Get the order value of this object.

protected synchronized BeanFactory
initFactory()

Initialize the view bean factory from the XML file.

protected View
loadView(String
the name of the view to retrieve
viewName
,
Locale
the Locale to retrieve the view for
locale
)

Implements abstract org.springframework.web.servlet.view.AbstractCachingViewResolver.loadView.

Subclasses must implement this method, building a View object for the specified view.

public void
setLocation(Resource
the location of the XML file.
location
)

Set the location of the XML file that defines the view beans.

public void
setOrder(int order)

Specify the order value for this ViewResolver bean.

Inherited from org.springframework.web.servlet.view.AbstractCachingViewResolver:
clearCachecreateViewgetCacheFiltergetCacheLimitisCacheisCacheUnresolvedremoveFromCacheresolveViewNamesetCachesetCacheFiltersetCacheLimitsetCacheUnresolved

Field Detail

cachedFactoryback to summary
private ConfigurableApplicationContext cachedFactory
Annotations
@Nullable
DEFAULT_LOCATIONback to summary
public static final String DEFAULT_LOCATION

Default if no other location is supplied.

locationback to summary
private Resource location
Annotations
@Nullable
orderback to summary
private int order

Constructor Detail

XmlViewResolverback to summary
public XmlViewResolver()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws BeansException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Pre-initialize the factory from the XML file. Only effective if caching is enabled.

Annotations
@Override
destroyback to summary
public void destroy() throws BeansException

Implements org.springframework.beans.factory.DisposableBean.destroy.

Close the view bean factory on context shutdown.

Annotations
@Override
getCacheKeyback to summary
protected Object getCacheKey(String viewName, Locale locale)

Overrides org.springframework.web.servlet.view.AbstractCachingViewResolver.getCacheKey.

This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.

Annotations
@Override
getOrderback to summary
public int getOrder()

Implements org.springframework.core.Ordered.getOrder.

Doc from org.springframework.core.Ordered.getOrder.

Get 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-startup values).

Same order values will result in arbitrary sort positions for the affected objects.

Returns:int

the order value

Annotations
@Override
initFactoryback to summary
protected synchronized BeanFactory initFactory() throws BeansException

Initialize the view bean factory from the XML file. Synchronized because of access by parallel threads.

Exceptions
BeansException:
in case of initialization errors
loadViewback to summary
protected View loadView(String viewName, Locale locale) throws BeansException

Implements abstract org.springframework.web.servlet.view.AbstractCachingViewResolver.loadView.

Doc from org.springframework.web.servlet.view.AbstractCachingViewResolver.loadView.

Subclasses 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.

Parameters
viewName:String

the name of the view to retrieve

locale:Locale

the Locale to retrieve the view for

Returns:View

the View instance, or null if not found (optional, to allow for ViewResolver chaining)

Annotations
@Override
setLocationback to summary
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:Resource

the location of the XML file.

setOrderback to summary
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
org.springframework.core.Ordered#getOrder()