类 ResourceBundleViewResolver
- 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.ResourceBundleViewResolver
- 所有已实现的接口:
Aware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Ordered
,ServletContextAware
,ViewResolver
public class ResourceBundleViewResolver extends AbstractCachingViewResolver implements Ordered, InitializingBean, DisposableBean
AViewResolver
implementation that uses bean definitions in aResourceBundle
, 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 ofPropertyResourceBundle
. 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 theOrdered
interface in order to allow for flexible participation inViewResolver
chaining. 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
.- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
ResourceBundle.getBundle(java.lang.String)
,PropertyResourceBundle
,UrlBasedViewResolver
嵌套类概要
从类继承的嵌套类/接口 org.springframework.web.servlet.view.AbstractCachingViewResolver
AbstractCachingViewResolver.CacheFilter
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_BASENAME
The default basename if no other basename is supplied.从类继承的字段 org.springframework.web.servlet.view.AbstractCachingViewResolver
DEFAULT_CACHE_LIMIT
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 ResourceBundleViewResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Eagerly initialize Locales if necessary.void
destroy()
Close the bundle View factories on context shutdown.protected ResourceBundle
getBundle(String basename, Locale locale)
Obtain the resource bundle for the given basename andLocale
.protected ClassLoader
getBundleClassLoader()
Return theClassLoader
to load resource bundles with.int
getOrder()
Get the order value of this object.protected BeanFactory
initFactory(Locale locale)
protected View
loadView(String viewName, Locale locale)
Subclasses must implement this method, building a View object for the specified view.void
setBasename(String basename)
Set a single basename, followingResourceBundle
conventions.void
setBasenames(String... basenames)
Set an array of basenames, each followingResourceBundle
conventions.void
setBundleClassLoader(ClassLoader classLoader)
Set theClassLoader
to load resource bundles with.void
setDefaultParentView(String defaultParentView)
Set the default parent for views defined in theResourceBundle
.void
setLocalesToInitialize(Locale... localesToInitialize)
Specify Locales to initialize eagerly, rather than lazily when actually accessed.void
setOrder(int order)
Specify the order value for this ViewResolver bean.从类继承的方法 org.springframework.web.servlet.view.AbstractCachingViewResolver
clearCache, createView, getCacheFilter, getCacheKey, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheFilter, setCacheLimit, setCacheUnresolved
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
字段详细资料
DEFAULT_BASENAME
public static final String DEFAULT_BASENAME
The default basename if no other basename is supplied.- 另请参阅:
- 常量字段值
构造器详细资料
ResourceBundleViewResolver
public ResourceBundleViewResolver()
方法详细资料
setBasename
public void setBasename(String basename)
Set a single basename, followingResourceBundle
conventions. The default is "views".ResourceBundle
supports different locale suffixes. For example, a base name of "views" might map toResourceBundle
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.
setBasenames
public void setBasenames(String... basenames)
Set an array of basenames, each followingResourceBundle
conventions. The default is a single basename "views".ResourceBundle
supports different locale suffixes. For example, a base name of "views" might map toResourceBundle
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.
setBundleClassLoader
public void setBundleClassLoader(ClassLoader classLoader)
Set theClassLoader
to load resource bundles with. Default is the thread contextClassLoader
.
getBundleClassLoader
protected ClassLoader getBundleClassLoader()
Return theClassLoader
to load resource bundles with.Default is the specified bundle
ClassLoader
, usually the thread contextClassLoader
.
setDefaultParentView
public void setDefaultParentView(String defaultParentView)
Set the default parent for views defined in theResourceBundle
.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.
setLocalesToInitialize
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.
setOrder
public void setOrder(int order)
Specify the order value for this ViewResolver bean.The default value is
Ordered.LOWEST_PRECEDENCE
, meaning non-ordered.- 另请参阅:
Ordered.getOrder()
getOrder
public int getOrder()
从接口复制的说明:Ordered
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.
- 指定者:
getOrder
在接口中Ordered
- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
afterPropertiesSet
public void afterPropertiesSet() throws BeansException
Eagerly initialize Locales if necessary.
loadView
protected View loadView(String viewName, Locale locale) throws Exception
从类复制的说明:AbstractCachingViewResolver
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.
- 指定者:
loadView
在类中AbstractCachingViewResolver
- 参数:
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for- 返回:
- the View instance, or
null
if not found (optional, to allow for ViewResolver chaining) - 抛出:
Exception
- if the view couldn't be resolved- 另请参阅:
AbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)
initFactory
protected BeanFactory initFactory(Locale locale) throws BeansException
Initialize the ViewBeanFactory
from theResourceBundle
, for the givenlocale
.Synchronized because of access by parallel threads.
- 参数:
locale
- the targetLocale
- 返回:
- the View factory for the given Locale
- 抛出:
BeansException
- in case of initialization errors
getBundle
protected ResourceBundle getBundle(String basename, Locale locale) throws MissingResourceException
Obtain the resource bundle for the given basename andLocale
.- 参数:
basename
- the basename to look forlocale
- theLocale
to look for- 返回:
- the corresponding
ResourceBundle
- 抛出:
MissingResourceException
- if no matching bundle could be found- 另请参阅:
ResourceBundle.getBundle(String, Locale, ClassLoader)
destroy
public void destroy() throws BeansException
Close the bundle View factories on context shutdown.- 指定者:
destroy
在接口中DisposableBean
- 抛出:
BeansException