Class ServletWebServerApplicationContext
- All Implemented Interfaces:
- Closeable, AutoCloseable, BeanFactory, HierarchicalBeanFactory, ListableBeanFactory, BeanDefinitionRegistry, ConfigurableWebServerApplicationContext, WebServerApplicationContext, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, AliasRegistry, EnvironmentCapable, ResourceLoader, ResourcePatternResolver, ConfigurableWebApplicationContext, WebApplicationContext
- Direct Known Subclasses:
- AnnotationConfigServletWebServerApplicationContext, XmlServletWebServerApplicationContext
WebApplicationContext that can be used to bootstrap itself from a contained
ServletWebServerFactory bean.
This context will create, initialize and run an WebServer by searching for a
single ServletWebServerFactory bean within the ApplicationContext
itself. The ServletWebServerFactory is free to use standard Spring concepts
(such as dependency injection, lifecycle callbacks and property placeholder variables).
In addition, any Servlet or Filter 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 often
ServletRegistrationBeans and/or FilterRegistrationBeans). To prevent
double registration, the use of ServletContextInitializer beans will disable
automatic Servlet and Filter bean registration.
Although this context can be used directly, most developers should consider using the
AnnotationConfigServletWebServerApplicationContext or
XmlServletWebServerApplicationContext variants.
- Since:
- 4.0.0
- Author:
- Phillip Webb, Dave Syer, Scott Frederick
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classUtility class to store and restore any user defined scopes.Nested classes/interfaces inherited from class DefaultResourceLoaderDefaultResourceLoader.ClassPathContextResource
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringConstant value for the DispatcherServlet bean name.Fields inherited from class AbstractApplicationContextAPPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, MESSAGE_SOURCE_BEAN_NAMEFields inherited from interface BeanFactoryFACTORY_BEAN_PREFIX, FACTORY_BEAN_PREFIX_CHARFields inherited from interface ConfigurableApplicationContextAPPLICATION_STARTUP_BEAN_NAME, BOOTSTRAP_EXECUTOR_BEAN_NAME, CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAMEFields inherited from interface ConfigurableWebApplicationContextAPPLICATION_CONTEXT_ID_PREFIX, SERVLET_CONFIG_BEAN_NAMEFields inherited from interface ResourceLoaderCLASSPATH_URL_PREFIXFields inherited from interface ResourcePatternResolverCLASSPATH_ALL_URL_PREFIXFields inherited from interface WebApplicationContextCONTEXT_ATTRIBUTES_BEAN_NAME, CONTEXT_PARAMETERS_BEAN_NAME, ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, SCOPE_APPLICATION, SCOPE_REQUEST, SCOPE_SESSION, SERVLET_CONTEXT_BEAN_NAMEFields inherited from interface WebServerApplicationContextGRACEFUL_SHUTDOWN_PHASE, START_STOP_LIFECYCLE_PHASE
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a newServletWebServerApplicationContext.Create a newServletWebServerApplicationContextwith the givenDefaultListableBeanFactory.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voiddoClose()protected ResourcegetResourceByPath(String path) @Nullable StringReturns the namespace of the web server application context ornullif no namespace has been set.@Nullable ServletConfig@Nullable WebServerReturns theWebServerthat was created by the context ornullif the server has not yet been created.protected ServletWebServerFactoryReturns theServletWebServerFactorythat should be used to create the embeddedWebServer.protected voidprotected voidpostProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) Register ServletContextAwareProcessor.final voidrefresh()voidsetServerNamespace(@Nullable String serverNamespace) Set the server namespace of the context.voidsetServletConfig(@Nullable ServletConfig servletConfig) Methods inherited from class GenericWebApplicationContextcreateEnvironment, getApplicationName, getConfigLocations, getNamespace, getResourcePatternResolver, getServletContext, initPropertySources, setConfigLocation, setConfigLocations, setNamespace, setServletContextMethods inherited from class GenericApplicationContextcancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getClassLoader, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanDefinitionOverridable, isBeanNameInUse, refreshBeanFactory, refreshForAotProcessing, register, registerAlias, registerBean, registerBean, registerBean, registerBean, registerBean, registerBean, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setApplicationStartup, setClassLoader, setParent, setResourceLoaderMethods inherited from class AbstractApplicationContextaddApplicationListener, addBeanFactoryPostProcessor, assertBeanFactoryActive, clearResourceCaches, close, containsBean, containsBeanDefinition, containsLocalBean, destroyBeans, findAllAnnotationsOnBean, findAnnotationOnBean, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationListeners, getApplicationStartup, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeanProvider, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getType, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isClosed, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, pause, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, registerBeanPostProcessors, registerListeners, registerShutdownHook, removeApplicationListener, resetCommonCaches, restart, setDisplayName, setEnvironment, setId, start, stop, toStringMethods inherited from class DefaultResourceLoaderaddProtocolResolver, getProtocolResolvers, getResourceCacheMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AliasRegistrygetAliasesMethods inherited from interface ApplicationContextgetApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDateMethods inherited from interface ApplicationEventPublisherpublishEvent, publishEventMethods inherited from interface BeanDefinitionRegistrycontainsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNamesMethods inherited from interface BeanFactorycontainsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getBeanProvider, getType, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatchMethods inherited from interface ConfigurableApplicationContextaddApplicationListener, addBeanFactoryPostProcessor, addProtocolResolver, close, getApplicationStartup, getBeanFactory, getEnvironment, isActive, isClosed, pause, registerShutdownHook, removeApplicationListener, restart, setApplicationStartup, setClassLoader, setEnvironment, setId, setParentMethods inherited from interface HierarchicalBeanFactorycontainsLocalBean, getParentBeanFactoryMethods inherited from interface ListableBeanFactorycontainsBeanDefinition, findAllAnnotationsOnBean, findAnnotationOnBean, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotationMethods inherited from interface MessageSourcegetMessage, getMessage, getMessageMethods inherited from interface ResourceLoadergetClassLoader, getResourceMethods inherited from interface ResourcePatternResolvergetResources
- 
Field Details- 
DISPATCHER_SERVLET_NAMEConstant 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 aServletRegistrationBeanor a different bean name.- See Also:
 
 
- 
- 
Constructor Details- 
ServletWebServerApplicationContextpublic ServletWebServerApplicationContext()Create a newServletWebServerApplicationContext.
- 
ServletWebServerApplicationContextCreate a newServletWebServerApplicationContextwith the givenDefaultListableBeanFactory.- Parameters:
- beanFactory- the DefaultListableBeanFactory instance to use for this context
 
 
- 
- 
Method Details- 
postProcessBeanFactoryRegister ServletContextAwareProcessor.- Overrides:
- postProcessBeanFactoryin class- GenericWebApplicationContext
- See Also:
 
- 
refresh- Specified by:
- refreshin interface- ConfigurableApplicationContext
- Overrides:
- refreshin class- AbstractApplicationContext
- Throws:
- BeansException
- IllegalStateException
 
- 
onRefreshprotected void onRefresh()- Overrides:
- onRefreshin class- AbstractApplicationContext
 
- 
doCloseprotected void doClose()- Overrides:
- doClosein class- AbstractApplicationContext
 
- 
getWebServerFactoryReturns theServletWebServerFactorythat should be used to create the embeddedWebServer. By default this method searches for a suitable bean in the context itself.- Returns:
- a ServletWebServerFactory(nevernull)
 
- 
getResourceByPath- Overrides:
- getResourceByPathin class- GenericWebApplicationContext
 
- 
getServerNamespaceDescription copied from interface:WebServerApplicationContextReturns the namespace of the web server application context ornullif 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).- Specified by:
- getServerNamespacein interface- WebServerApplicationContext
- Returns:
- the server namespace
 
- 
setServerNamespaceDescription copied from interface:ConfigurableWebServerApplicationContextSet the server namespace of the context.- Specified by:
- setServerNamespacein interface- ConfigurableWebServerApplicationContext
- Parameters:
- serverNamespace- the server namespace
- See Also:
 
- 
setServletConfig- Specified by:
- setServletConfigin interface- ConfigurableWebApplicationContext
- Overrides:
- setServletConfigin class- GenericWebApplicationContext
 
- 
getServletConfig- Specified by:
- getServletConfigin interface- ConfigurableWebApplicationContext
- Overrides:
- getServletConfigin class- GenericWebApplicationContext
 
- 
getWebServerReturns theWebServerthat was created by the context ornullif the server has not yet been created.- Specified by:
- getWebServerin interface- WebServerApplicationContext
- Returns:
- the embedded web server
 
 
-