类 InfraHandler
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.context.ApplicationContextAware,cn.taketoday.context.EnvironmentAware,cn.taketoday.core.env.EnvironmentCapable
- 直接已知子类:
DispatcherHandler
- 从以下版本开始:
- 4.0 2022/9/26 23:21
- 作者:
- Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private classApplicationListener endpoint that receives events from this handler's ApplicationContext only, delegating toonApplicationEventon the DispatcherHandler instance. -
字段概要
字段修饰符和类型字段说明static final StringPrefix for ApplicationContext ids that refer to context path and/or servlet name.private cn.taketoday.context.ApplicationContextprivate booleanIf the ApplicationContext was injected viasetApplicationContext(cn.taketoday.context.ApplicationContext).protected Stringprivate Class<?>ApplicationContext implementation class to create.private StringExplicit context config location.private StringApplicationContext id to assign.private StringComma-delimited ApplicationContextInitializer class names set through init param.private final ArrayList<cn.taketoday.context.ApplicationContextInitializer>Actual ApplicationContextInitializer instances to apply to the context.static final Class<?>Default context class for InfraHandler.private booleanWhether to log potentially sensitive info (request params at DEBUG + headers at TRACE).private cn.taketoday.core.env.ConfigurableEnvironmentstatic final StringAny number of these characters are considered delimiters between multiple values in a single init-param String value.protected final AtomicBooleanprotected final cn.taketoday.logging.Loggerprivate final ObjectMonitor for synchronized onRefresh execution.private booleanFlag used to detect whether onRefresh has already been called. -
构造器概要
构造器限定符构造器说明protectedprotectedInfraHandler(cn.taketoday.context.ApplicationContext applicationContext) Create a newInfraHandlerwith the given application context. -
方法概要
修饰符和类型方法说明protected voidThis method will be invoked after any bean properties have been set and the ApplicationContext has been loaded.protected voidapplyDefaultContextId(cn.taketoday.context.ConfigurableApplicationContext context) protected voidapplyInitializers(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.context.ApplicationContextInitializer> initializers) Delegate the ApplicationContext before it is refreshed to anyApplicationContextInitializerinstances specified by the "contextInitializerClasses" servlet init-param.protected voidconfigureAndRefreshApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context) protected cn.taketoday.context.ApplicationContextcreateApplicationContext(cn.taketoday.context.ApplicationContext parent) Instantiate the ApplicationContext for this handler, either a defaultXmlWebApplicationContextor acustom context class, if set.protected cn.taketoday.core.env.ConfigurableEnvironmentCreate and return a newStandardEnvironment.voiddestroy()Destroy Applicationprotected cn.taketoday.context.ApplicationContextRetrieve aApplicationContextfinal cn.taketoday.context.ApplicationContextReturn this handler's ApplicationContext.Class<?>Return the custom context class.Return the explicit context config location, if any.Return the custom ApplicationContext id, if any.cn.taketoday.core.env.ConfigurableEnvironmentReturn theEnvironmentassociated with this handler.protected cn.taketoday.context.ApplicationContextvoidinit()protected cn.taketoday.context.ApplicationContextInitialize and publish the ApplicationContext for this handler.booleanWhether logging of potentially sensitive, request details at DEBUG and TRACE level is allowed.protected final cn.taketoday.context.ApplicationContextInitializerloadInitializer(String className, cn.taketoday.context.ConfigurableApplicationContext context) protected voidLog internalvoidonApplicationEvent(cn.taketoday.context.event.ContextRefreshedEvent event) Callback that receives refresh events from this handler's ApplicationContext.protected voidonRefresh(cn.taketoday.context.ApplicationContext context) Template method which can be overridden to add servlet-specific refresh work.protected voidpostProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context) Post-process the given ApplicationContext before it is refreshed and activated as context for this handler.voidrefresh()Refresh this handler's application context, as well as the dependent state of the handler.voidsetApplicationContext(cn.taketoday.context.ApplicationContext applicationContext) Called by Infra viaApplicationContextAwareto inject the current application context.voidsetBeanName(String name) voidsetContextClass(Class<?> contextClass) Set a custom context class.voidsetContextConfigLocation(String contextConfigLocation) Set the context config location explicitly, instead of relying on the default location built from the namespace.voidsetContextId(String contextId) Specify a custom ApplicationContext id, to be used as serialization id for the underlying BeanFactory.voidsetContextInitializerClasses(String contextInitializerClasses) Specify the set of fully-qualifiedApplicationContextInitializerclass names, per the optional "contextInitializerClasses" servlet init-param.voidsetContextInitializers(cn.taketoday.context.ApplicationContextInitializer... initializers) Specify whichApplicationContextInitializerinstances should be used to initialize the application context used by thisInfraHandler.voidsetEnableLoggingRequestDetails(boolean enable) Whether to log request params at DEBUG level, and headers at TRACE level.voidsetEnvironment(cn.taketoday.core.env.Environment environment) Set theEnvironmentthat this handler runs in.
-
字段详细资料
-
DEFAULT_CONTEXT_CLASS
Default context class for InfraHandler.- 另请参阅:
-
ClassPathXmlApplicationContext
-
APPLICATION_CONTEXT_ID_PREFIX
Prefix for ApplicationContext ids that refer to context path and/or servlet name. -
INIT_PARAM_DELIMITERS
Any number of these characters are considered delimiters between multiple values in a single init-param String value.- 另请参阅:
-
log
protected final cn.taketoday.logging.Logger log -
applicationContextInjected
private boolean applicationContextInjectedIf the ApplicationContext was injected viasetApplicationContext(cn.taketoday.context.ApplicationContext). -
contextClass
ApplicationContext implementation class to create. -
contextId
ApplicationContext id to assign. -
contextConfigLocation
Explicit context config location. -
contextInitializers
Actual ApplicationContextInitializer instances to apply to the context. -
contextInitializerClasses
Comma-delimited ApplicationContextInitializer class names set through init param. -
refreshEventReceived
private volatile boolean refreshEventReceivedFlag used to detect whether onRefresh has already been called. -
onRefreshMonitor
Monitor for synchronized onRefresh execution. -
beanName
-
environment
@Nullable private cn.taketoday.core.env.ConfigurableEnvironment environment -
applicationContext
private cn.taketoday.context.ApplicationContext applicationContext -
enableLoggingRequestDetails
private boolean enableLoggingRequestDetailsWhether to log potentially sensitive info (request params at DEBUG + headers at TRACE). -
initialized
-
-
构造器详细资料
-
InfraHandler
protected InfraHandler() -
InfraHandler
protected InfraHandler(cn.taketoday.context.ApplicationContext applicationContext) Create a newInfraHandlerwith the given application context.Using this constructor indicates that the following properties / init-params will be ignored:
setContextClass(Class)/ 'contextClass'setContextConfigLocation(String)/ 'contextConfigLocation'
The given application context may or may not yet be refreshed. If it (a) is an implementation of
ConfigurableApplicationContextand (b) has not already been refreshed (the recommended approach), then the following will occur:- If the given context does not already have a parent, the root application context will be set as the parent.
- If the given context has not already been assigned an id, one will be assigned to it
ServletContextandServletConfigobjects will be delegated to the application contextpostProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext)will be called- Any
ApplicationContextInitializersspecified through the "contextInitializerClasses" init-param or through thesetContextInitializers(cn.taketoday.context.ApplicationContextInitializer...)property will be applied. refresh()will be called
ConfigurableApplicationContext, none of the above will occur under the assumption that the user has performed these actions (or not) per his or her specific needs.- 参数:
applicationContext- the context to use- 另请参阅:
-
-
方法详细资料
-
setBeanName
- 指定者:
setBeanName在接口中cn.taketoday.beans.factory.BeanNameAware
-
setEnvironment
public void setEnvironment(cn.taketoday.core.env.Environment environment) Set theEnvironmentthat this handler runs in.Any environment set here overrides the
StandardEnvironmentprovided by default.- 指定者:
setEnvironment在接口中cn.taketoday.context.EnvironmentAware- 抛出:
IllegalArgumentException- if environment is not assignable toConfigurableEnvironment
-
getEnvironment
public cn.taketoday.core.env.ConfigurableEnvironment getEnvironment()Return theEnvironmentassociated with this handler.If none specified, a default environment will be initialized via
createEnvironment().- 指定者:
getEnvironment在接口中cn.taketoday.core.env.EnvironmentCapable
-
createEnvironment
protected cn.taketoday.core.env.ConfigurableEnvironment createEnvironment()Create and return a newStandardEnvironment.Subclasses may override this in order to configure the environment or specialize the environment type returned.
-
init
public void init() -
afterApplicationContextInit
protected void afterApplicationContextInit()This method will be invoked after any bean properties have been set and the ApplicationContext has been loaded. The default implementation is empty; subclasses may override this method to perform any initialization they require. -
initApplicationContext
protected cn.taketoday.context.ApplicationContext initApplicationContext()Initialize and publish the ApplicationContext for this handler.Delegates to
createApplicationContext(cn.taketoday.context.ApplicationContext)for actual creation of the context. Can be overridden in subclasses.- 返回:
- the ApplicationContext instance
- 另请参阅:
-
getRootApplicationContext
@Nullable protected cn.taketoday.context.ApplicationContext getRootApplicationContext() -
configureAndRefreshApplicationContext
protected void configureAndRefreshApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context) -
applyDefaultContextId
protected void applyDefaultContextId(cn.taketoday.context.ConfigurableApplicationContext context) -
findApplicationContext
@Nullable protected cn.taketoday.context.ApplicationContext findApplicationContext()Retrieve aApplicationContext- 返回:
- the ApplicationContext for this handler, or
nullif not found
-
createApplicationContext
protected cn.taketoday.context.ApplicationContext createApplicationContext(@Nullable cn.taketoday.context.ApplicationContext parent) Instantiate the ApplicationContext for this handler, either a defaultXmlWebApplicationContextor acustom context class, if set.This implementation expects custom contexts to implement the
ConfigurableApplicationContextinterface. Can be overridden in subclasses.Do not forget to register this handler instance as application listener on the created context (for triggering its
callback), and to callConfigurableApplicationContext.refresh()before returning the context instance.- 参数:
parent- the parent ApplicationContext to use, ornullif none- 返回:
- the ApplicationContext for this handler
- 另请参阅:
-
postProcessApplicationContext
protected void postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context) Post-process the given ApplicationContext before it is refreshed and activated as context for this handler.The default implementation is empty.
refresh()will be called automatically after this method returns.Note that this method is designed to allow subclasses to modify the application context, while
initApplicationContext()is designed to allow end-users to modify the context through the use ofApplicationContextInitializers.- 参数:
context- the configured ApplicationContext (not refreshed yet)- 另请参阅:
-
createApplicationContext(cn.taketoday.context.ApplicationContext)initApplicationContext()ConfigurableApplicationContext.refresh()
-
applyInitializers
protected void applyInitializers(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.context.ApplicationContextInitializer> initializers) Delegate the ApplicationContext before it is refreshed to anyApplicationContextInitializerinstances specified by the "contextInitializerClasses" servlet init-param.See also
postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext), which is designed to allow subclasses (as opposed to end-users) to modify the application context, and is called immediately before this method.- 参数:
context- the configured ApplicationContext (not refreshed yet)initializers- ApplicationContextInitializer list- 另请参阅:
-
createApplicationContext(cn.taketoday.context.ApplicationContext)postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext)ConfigurableApplicationContext.refresh()
-
loadInitializer
protected final cn.taketoday.context.ApplicationContextInitializer loadInitializer(String className, cn.taketoday.context.ConfigurableApplicationContext context) -
refresh
public void refresh()Refresh this handler's application context, as well as the dependent state of the handler.- 另请参阅:
-
getApplicationContext()ConfigurableApplicationContext.refresh()
-
onRefresh
protected void onRefresh(cn.taketoday.context.ApplicationContext context) Template method which can be overridden to add servlet-specific refresh work. Called after successful context refresh.This implementation is empty.
- 参数:
context- the current ApplicationContext- 另请参阅:
-
destroy
public void destroy()Destroy Application -
logInfo
Log internal- 参数:
msg- Log message
-
onApplicationEvent
public void onApplicationEvent(cn.taketoday.context.event.ContextRefreshedEvent event) Callback that receives refresh events from this handler's ApplicationContext.The default implementation calls
onRefresh(cn.taketoday.context.ApplicationContext), triggering a refresh of this handler's context-dependent state.- 参数:
event- the incoming ApplicationContext event
-
setApplicationContext
public void setApplicationContext(cn.taketoday.context.ApplicationContext applicationContext) Called by Infra viaApplicationContextAwareto inject the current application context. This method allows DispatcherServlets to be registered as Infra beans inside an existingApplicationContextrather thanfindingabootstrappedcontext.Primarily added to support use in embedded handler containers.
- 指定者:
setApplicationContext在接口中cn.taketoday.context.ApplicationContextAware
-
getApplicationContext
public final cn.taketoday.context.ApplicationContext getApplicationContext()Return this handler's ApplicationContext. -
setContextClass
Set a custom context class. This class must be of typeApplicationContext.When using the default DispatcherHandler implementation, the context class must also implement the
ConfigurableApplicationContextinterface. -
getContextClass
Return the custom context class. -
setContextId
Specify a custom ApplicationContext id, to be used as serialization id for the underlying BeanFactory. -
getContextId
Return the custom ApplicationContext id, if any. -
setContextConfigLocation
Set the context config location explicitly, instead of relying on the default location built from the namespace. This location string can consist of multiple locations separated by any number of commas and spaces. -
getContextConfigLocation
Return the explicit context config location, if any. -
setContextInitializers
public void setContextInitializers(@Nullable cn.taketoday.context.ApplicationContextInitializer... initializers) Specify whichApplicationContextInitializerinstances should be used to initialize the application context used by thisInfraHandler. -
setContextInitializerClasses
Specify the set of fully-qualifiedApplicationContextInitializerclass names, per the optional "contextInitializerClasses" servlet init-param. -
setEnableLoggingRequestDetails
public void setEnableLoggingRequestDetails(boolean enable) Whether to log request params at DEBUG level, and headers at TRACE level. Both may contain sensitive information.By default set to
falseso that request details are not shown.- 参数:
enable- whether to enable or not
-
isEnableLoggingRequestDetails
public boolean isEnableLoggingRequestDetails()Whether logging of potentially sensitive, request details at DEBUG and TRACE level is allowed.
-