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

public Class ResourceBundleViewResolver

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.ArrayList, .HashMap, .List, .Locale, .Map, .MissingResourceException, .ResourceBundle, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .DisposableBean, .InitializingBean, .NoSuchBeanDefinitionException, org.springframework.context.ConfigurableApplicationContext, org.springframework.core.Ordered, 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 ResourceBundle, specified by the bundle basename.

The bundle is typically defined in a properties file, located in the classpath. The default bundle basename is "views".

This ViewResolver supports localized view definitions, using the default support of java.util.PropertyResourceBundle. For example, the basename "views" will be resolved as class path resources "views_de_AT.properties", "views_de.properties", "views.properties" - for a given Locale "de_AT".

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.

Authors
Rod Johnson, Juergen Hoeller
See Also
java.util.ResourceBundle#getBundle, java.util.PropertyResourceBundle, UrlBasedViewResolver, BeanNameViewResolver

Field Summary

Modifier and TypeField and Description
private String[]
private final Map<List<ResourceBundle>, ConfigurableApplicationContext>
private ClassLoader
public static final String
DEFAULT_BASENAME

The default basename if no other basename is supplied.

private String
private final Map<Locale, BeanFactory>
private Locale[]
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
public void
destroy()

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

Close the bundle View factories on context shutdown.

protected ResourceBundle

Returns:

the corresponding ResourceBundle
getBundle
(String
the basename to look for
basename
,
Locale
the Locale to look for
locale
)

Obtain the resource bundle for the given basename and Locale.

protected ClassLoader
getBundleClassLoader()

Return the ClassLoader to load resource bundles with.

public int
getOrder()

Implements org.springframework.core.Ordered.getOrder.

Get the order value of this object.

protected synchronized BeanFactory

Returns:

the View factory for the given Locale
initFactory
(Locale
the target Locale
locale
)

Initialize the View BeanFactory from the ResourceBundle, for the given locale.

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
setBasename(String basename)

Set a single basename, following java.util.ResourceBundle conventions.

public void
setBasenames(String... basenames)

Set an array of basenames, each following java.util.ResourceBundle conventions.

public void
setBundleClassLoader(ClassLoader classLoader)

Set the ClassLoader to load resource bundles with.

public void
setDefaultParentView(String defaultParentView)

Set the default parent for views defined in the ResourceBundle.

public void
setLocalesToInitialize(Locale... localesToInitialize)

Specify Locales to initialize eagerly, rather than lazily when actually accessed.

public void
setOrder(int order)

Specify the order value for this ViewResolver bean.

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

Field Detail

basenamesback to summary
private String[] basenames
bundleCacheback to summary
private final Map<List<ResourceBundle>, ConfigurableApplicationContext> bundleCache
bundleClassLoaderback to summary
private ClassLoader bundleClassLoader
DEFAULT_BASENAMEback to summary
public static final String DEFAULT_BASENAME

The default basename if no other basename is supplied.

defaultParentViewback to summary
private String defaultParentView
Annotations
@Nullable
localeCacheback to summary
private final Map<Locale, BeanFactory> localeCache
localesToInitializeback to summary
private Locale[] localesToInitialize
Annotations
@Nullable
orderback to summary
private int order

Constructor Detail

ResourceBundleViewResolverback to summary
public ResourceBundleViewResolver()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws BeansException

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

Eagerly initialize Locales if necessary.

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

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

Close the bundle View factories on context shutdown.

Annotations
@Override
getBundleback to summary
protected ResourceBundle getBundle(String basename, Locale locale) throws MissingResourceException

Obtain the resource bundle for the given basename and Locale.

Parameters
basename:String

the basename to look for

locale:Locale

the Locale to look for

Returns:ResourceBundle

the corresponding ResourceBundle

Exceptions
MissingResourceException:
if no matching bundle could be found
See Also
ResourceBundle#getBundle(String, Locale, ClassLoader)
getBundleClassLoaderback to summary
protected ClassLoader getBundleClassLoader()

Return the ClassLoader to load resource bundles with.

Default is the specified bundle ClassLoader, usually the thread context ClassLoader.

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(Locale locale) throws BeansException

Initialize the View BeanFactory from the ResourceBundle, for the given locale.

Synchronized because of access by parallel threads.

Parameters
locale:Locale

the target Locale

Returns:BeanFactory

the View factory for the given Locale

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

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
Exceptions
Exception:
if the view couldn't be resolved
setBasenameback to summary
public void setBasename(String basename)

Set a single basename, following java.util.ResourceBundle conventions. The default is "views".

ResourceBundle supports different locale suffixes. For example, a base name of "views" might map to ResourceBundle files "views", "views_en_au" and "views_de".

Note that ResourceBundle names are effectively classpath locations: As a consequence, the JDK's standard ResourceBundle treats dots as package separators. This means that "test.theme" is effectively equivalent to "test/theme", just like it is for programmatic java.util.ResourceBundle usage.

See Also
setBasenames, ResourceBundle#getBundle(String), ResourceBundle#getBundle(String, Locale)
setBasenamesback to summary
public void setBasenames(String... basenames)

Set an array of basenames, each following java.util.ResourceBundle conventions. The default is a single basename "views".

ResourceBundle supports different locale suffixes. For example, a base name of "views" might map to ResourceBundle files "views", "views_en_au" and "views_de".

The associated resource bundles will be checked sequentially when resolving a message code. Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.

Note that ResourceBundle names are effectively classpath locations: As a consequence, the JDK's standard ResourceBundle treats dots as package separators. This means that "test.theme" is effectively equivalent to "test/theme", just like it is for programmatic java.util.ResourceBundle usage.

See Also
setBasename, ResourceBundle#getBundle(String), ResourceBundle#getBundle(String, Locale)
setBundleClassLoaderback to summary
public void setBundleClassLoader(ClassLoader classLoader)

Set the ClassLoader to load resource bundles with. Default is the thread context ClassLoader.

setDefaultParentViewback to summary
public void setDefaultParentView(String defaultParentView)

Set the default parent for views defined in the ResourceBundle.

This avoids repeated "yyy1.(parent)=xxx", "yyy2.(parent)=xxx" definitions in the bundle, especially if all defined views share the same parent.

The parent will typically define the view class and common attributes. Concrete views might simply consist of a URL definition then: a la "yyy1.url=/my.jsp", "yyy2.url=/your.jsp".

View definitions that define their own parent or carry their own class can still override this. Strictly speaking, the rule that a default parent setting does not apply to a bean definition that carries a class is there for backwards compatibility reasons. It still matches the typical use case.

setLocalesToInitializeback to summary
public void setLocalesToInitialize(Locale... localesToInitialize)

Specify Locales to initialize eagerly, rather than lazily when actually accessed.

Allows for pre-initialization of common Locales, eagerly checking the view configuration for those Locales.

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()