类 ServletWebServerApplicationContext
- java.lang.Object
- org.springframework.core.io.DefaultResourceLoader
- org.springframework.context.support.AbstractApplicationContext
- org.springframework.context.support.GenericApplicationContext
- org.springframework.web.context.support.GenericWebApplicationContext
- org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
- 所有已实现的接口:
Closeable
,AutoCloseable
,org.springframework.beans.factory.BeanFactory
,org.springframework.beans.factory.HierarchicalBeanFactory
,org.springframework.beans.factory.ListableBeanFactory
,org.springframework.beans.factory.support.BeanDefinitionRegistry
,ConfigurableWebServerApplicationContext
,WebServerApplicationContext
,org.springframework.context.ApplicationContext
,org.springframework.context.ApplicationEventPublisher
,org.springframework.context.ConfigurableApplicationContext
,org.springframework.context.Lifecycle
,org.springframework.context.MessageSource
,org.springframework.core.AliasRegistry
,org.springframework.core.env.EnvironmentCapable
,org.springframework.core.io.ResourceLoader
,org.springframework.core.io.support.ResourcePatternResolver
,org.springframework.ui.context.ThemeSource
,org.springframework.web.context.ConfigurableWebApplicationContext
,org.springframework.web.context.WebApplicationContext
public class ServletWebServerApplicationContext extends org.springframework.web.context.support.GenericWebApplicationContext implements ConfigurableWebServerApplicationContext
AWebApplicationContext
that can be used to bootstrap itself from a containedServletWebServerFactory
bean.This context will create, initialize and run an
WebServer
by searching for a singleServletWebServerFactory
bean within theApplicationContext
itself. TheServletWebServerFactory
is free to use standard Spring concepts (such as dependency injection, lifecycle callbacks and property placeholder variables).In addition, any
Servlet
orFilter
beans defined in the context will be automatically registered with the web server. In the case of a single Servlet bean, the '/' mapping will be used. If multiple Servlet beans are found then the lowercase bean name will be used as a mapping prefix. Any Servlet named 'dispatcherServlet' will always be mapped to '/'. Filter beans will be mapped to all URLs ('/*').For more advanced configuration, the context can instead define beans that implement the
ServletContextInitializer
interface (most oftenServletRegistrationBean
s and/orFilterRegistrationBean
s). To prevent double registration, the use ofServletContextInitializer
beans will disable automatic Servlet and Filter bean registration.Although this context can be used directly, most developers should consider using the
AnnotationConfigServletWebServerApplicationContext
orXmlServletWebServerApplicationContext
variants.
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
ServletWebServerApplicationContext.ExistingWebApplicationScopes
Utility class to store and restore any user defined scopes.
字段概要
字段 修饰符和类型 字段 说明 static String
DISPATCHER_SERVLET_NAME
Constant value for the DispatcherServlet bean name.从类继承的字段 org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, MESSAGE_SOURCE_BEAN_NAME
从接口继承的字段 org.springframework.context.ConfigurableApplicationContext
CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
构造器概要
构造器 构造器 说明 ServletWebServerApplicationContext()
Create a newServletWebServerApplicationContext
.ServletWebServerApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory beanFactory)
Create a newServletWebServerApplicationContext
with the givenDefaultListableBeanFactory
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
finishRefresh()
protected org.springframework.core.io.Resource
getResourceByPath(String path)
String
getServerNamespace()
Returns the namespace of the web server application context ornull
if no namespace has been set.javax.servlet.ServletConfig
getServletConfig()
protected Collection<ServletContextInitializer>
getServletContextInitializerBeans()
ReturnsServletContextInitializer
s that should be used with the embedded web server.WebServer
getWebServer()
Returns theWebServer
that was created by the context ornull
if the server has not yet been created.protected ServletWebServerFactory
getWebServerFactory()
Returns theServletWebServerFactory
that should be used to create the embeddedWebServer
.protected void
onClose()
protected void
onRefresh()
protected void
postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Register ServletContextAwareProcessor.protected void
prepareWebApplicationContext(javax.servlet.ServletContext servletContext)
Prepare theWebApplicationContext
with the given fully loadedServletContext
.void
refresh()
void
setServerNamespace(String serverNamespace)
Set the server namespace of the context.void
setServletConfig(javax.servlet.ServletConfig servletConfig)
从类继承的方法 org.springframework.web.context.support.GenericWebApplicationContext
createEnvironment, getApplicationName, getConfigLocations, getNamespace, getResourcePatternResolver, getServletContext, getTheme, initPropertySources, setConfigLocation, setConfigLocations, setNamespace, setServletContext
从类继承的方法 org.springframework.context.support.GenericApplicationContext
cancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getClassLoader, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanNameInUse, refreshBeanFactory, registerAlias, registerBean, registerBean, registerBean, registerBean, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setClassLoader, setParent, setResourceLoader
从类继承的方法 org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, assertBeanFactoryActive, close, containsBean, containsBeanDefinition, containsLocalBean, destroy, destroyBeans, doClose, findAnnotationOnBean, finishBeanFactoryInitialization, getAliases, getApplicationListeners, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setDisplayName, setEnvironment, setId, start, stop, toString
从类继承的方法 org.springframework.core.io.DefaultResourceLoader
addProtocolResolver, clearResourceCaches, getProtocolResolvers, getResourceCache
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.context.ApplicationContext
getApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
从接口继承的方法 org.springframework.beans.factory.support.BeanDefinitionRegistry
containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames
从接口继承的方法 org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch
从接口继承的方法 org.springframework.context.ConfigurableApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, addProtocolResolver, close, getBeanFactory, getEnvironment, isActive, registerShutdownHook, setEnvironment, setId, setParent
从接口继承的方法 org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
从接口继承的方法 org.springframework.beans.factory.ListableBeanFactory
containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation
字段详细资料
DISPATCHER_SERVLET_NAME
public static final String DISPATCHER_SERVLET_NAME
Constant value for the DispatcherServlet bean name. A Servlet bean with this name is deemed to be the "main" servlet and is automatically given a mapping of "/" by default. To change the default behavior you can use aServletRegistrationBean
or a different bean name.- 另请参阅:
- 常量字段值
构造器详细资料
ServletWebServerApplicationContext
public ServletWebServerApplicationContext()
Create a newServletWebServerApplicationContext
.
ServletWebServerApplicationContext
public ServletWebServerApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory beanFactory)
Create a newServletWebServerApplicationContext
with the givenDefaultListableBeanFactory
.- 参数:
beanFactory
- the DefaultListableBeanFactory instance to use for this context
方法详细资料
postProcessBeanFactory
protected void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Register ServletContextAwareProcessor.- 覆盖:
postProcessBeanFactory
在类中org.springframework.web.context.support.GenericWebApplicationContext
- 另请参阅:
ServletContextAwareProcessor
refresh
public final void refresh() throws org.springframework.beans.BeansException, IllegalStateException
- 指定者:
refresh
在接口中org.springframework.context.ConfigurableApplicationContext
- 覆盖:
refresh
在类中org.springframework.context.support.AbstractApplicationContext
- 抛出:
org.springframework.beans.BeansException
IllegalStateException
onRefresh
protected void onRefresh()
- 覆盖:
onRefresh
在类中org.springframework.web.context.support.GenericWebApplicationContext
finishRefresh
protected void finishRefresh()
- 覆盖:
finishRefresh
在类中org.springframework.context.support.AbstractApplicationContext
onClose
protected void onClose()
- 覆盖:
onClose
在类中org.springframework.context.support.AbstractApplicationContext
getWebServerFactory
protected ServletWebServerFactory getWebServerFactory()
Returns theServletWebServerFactory
that should be used to create the embeddedWebServer
. By default this method searches for a suitable bean in the context itself.- 返回:
- a
ServletWebServerFactory
(nevernull
)
getServletContextInitializerBeans
protected Collection<ServletContextInitializer> getServletContextInitializerBeans()
ReturnsServletContextInitializer
s that should be used with the embedded web server. By default this method will first attempt to findServletContextInitializer
,Servlet
,Filter
and certainEventListener
beans.- 返回:
- the servlet initializer beans
prepareWebApplicationContext
protected void prepareWebApplicationContext(javax.servlet.ServletContext servletContext)
Prepare theWebApplicationContext
with the given fully loadedServletContext
. This method is usually called fromServletContextInitializer.onStartup(ServletContext)
and is similar to the functionality usually provided by aContextLoaderListener
.- 参数:
servletContext
- the operational servlet context
getResourceByPath
protected org.springframework.core.io.Resource getResourceByPath(String path)
- 覆盖:
getResourceByPath
在类中org.springframework.web.context.support.GenericWebApplicationContext
getServerNamespace
public String getServerNamespace()
从接口复制的说明:WebServerApplicationContext
Returns the namespace of the web server application context ornull
if no namespace has been set. Used for disambiguation when multiple web servers are running in the same application (for example a management context running on a different port).- 指定者:
getServerNamespace
在接口中WebServerApplicationContext
- 返回:
- the server namespace
setServerNamespace
public void setServerNamespace(String serverNamespace)
从接口复制的说明:ConfigurableWebServerApplicationContext
Set the server namespace of the context.- 指定者:
setServerNamespace
在接口中ConfigurableWebServerApplicationContext
- 参数:
serverNamespace
- the server namespace- 另请参阅:
WebServerApplicationContext.getServerNamespace()
setServletConfig
public void setServletConfig(javax.servlet.ServletConfig servletConfig)
- 指定者:
setServletConfig
在接口中org.springframework.web.context.ConfigurableWebApplicationContext
- 覆盖:
setServletConfig
在类中org.springframework.web.context.support.GenericWebApplicationContext
getServletConfig
public javax.servlet.ServletConfig getServletConfig()
- 指定者:
getServletConfig
在接口中org.springframework.web.context.ConfigurableWebApplicationContext
- 覆盖:
getServletConfig
在类中org.springframework.web.context.support.GenericWebApplicationContext
getWebServer
public WebServer getWebServer()
Returns theWebServer
that was created by the context ornull
if the server has not yet been created.- 指定者:
getWebServer
在接口中WebServerApplicationContext
- 返回:
- the embedded web server