public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
WebApplicationContext
that can be used to bootstrap itself from a contained
EmbeddedServletContainerFactory
bean.
This context will create, initialize and run an EmbeddedServletContainer
by
searching for a single EmbeddedServletContainerFactory
bean within the
ApplicationContext
itself. The EmbeddedServletContainerFactory
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 embedded Servlet container. 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
ServletRegistrationBean
s and/or FilterRegistrationBean
s). 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
AnnotationConfigEmbeddedWebApplicationContext
or
XmlEmbeddedWebApplicationContext
variants.
AnnotationConfigEmbeddedWebApplicationContext
,
XmlEmbeddedWebApplicationContext
,
EmbeddedServletContainerFactory
Modifier and Type | Class and Description |
---|---|
static class |
EmbeddedWebApplicationContext.ExistingWebApplicationScopes
Utility class to store and restore any user defined scopes.
|
DefaultResourceLoader.ClassPathContextResource
Modifier and Type | Field and Description |
---|---|
static String |
DISPATCHER_SERVLET_NAME
Constant value for the DispatcherServlet bean name.
|
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, MESSAGE_SOURCE_BEAN_NAME
APPLICATION_CONTEXT_ID_PREFIX, SERVLET_CONFIG_BEAN_NAME
CONTEXT_ATTRIBUTES_BEAN_NAME, CONTEXT_PARAMETERS_BEAN_NAME, ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, SCOPE_APPLICATION, SCOPE_GLOBAL_SESSION, SCOPE_REQUEST, SCOPE_SESSION, SERVLET_CONTEXT_BEAN_NAME
CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
FACTORY_BEAN_PREFIX
CLASSPATH_ALL_URL_PREFIX
CLASSPATH_URL_PREFIX
Constructor and Description |
---|
EmbeddedWebApplicationContext() |
Modifier and Type | Method and Description |
---|---|
protected void |
finishRefresh() |
EmbeddedServletContainer |
getEmbeddedServletContainer()
Returns the
EmbeddedServletContainer that was created by the context or
null if the container has not yet been created. |
protected EmbeddedServletContainerFactory |
getEmbeddedServletContainerFactory()
Returns the
EmbeddedServletContainerFactory that should be used to create
the embedded servlet container. |
String |
getNamespace() |
protected Resource |
getResourceByPath(String path) |
ServletConfig |
getServletConfig() |
protected Collection<ServletContextInitializer> |
getServletContextInitializerBeans()
Returns
ServletContextInitializer s that should be used with the embedded
Servlet context. |
protected void |
onClose() |
protected void |
onRefresh() |
protected void |
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Register ServletContextAwareProcessor.
|
protected void |
prepareEmbeddedWebApplicationContext(ServletContext servletContext)
Prepare the
WebApplicationContext with the given fully loaded
ServletContext . |
void |
refresh() |
void |
setNamespace(String namespace) |
void |
setServletConfig(ServletConfig servletConfig) |
createEnvironment, getApplicationName, getConfigLocations, getResourcePatternResolver, getServletContext, getTheme, initPropertySources, setConfigLocation, setConfigLocations, setServletContext
cancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanNameInUse, refreshBeanFactory, registerAlias, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setId, setParent, setResourceLoader
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, 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, start, stop, toString
getClassLoader, setClassLoader
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, getEnvironment, isActive, registerShutdownHook, setEnvironment, setId, setParent
getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation
containsLocalBean, getParentBeanFactory
containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch
getMessage, getMessage, getMessage
publishEvent, publishEvent
getResources
getClassLoader, getResource
containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames
getAliases
public static final String DISPATCHER_SERVLET_NAME
ServletRegistrationBean
or a different bean name.protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
postProcessBeanFactory
in class GenericWebApplicationContext
ServletContextAwareProcessor
public final void refresh() throws BeansException, IllegalStateException
refresh
in interface ConfigurableApplicationContext
refresh
in class AbstractApplicationContext
BeansException
IllegalStateException
protected void onRefresh()
onRefresh
in class GenericWebApplicationContext
protected void finishRefresh()
finishRefresh
in class AbstractApplicationContext
protected void onClose()
onClose
in class AbstractApplicationContext
protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory()
EmbeddedServletContainerFactory
that should be used to create
the embedded servlet container. By default this method searches for a suitable bean
in the context itself.EmbeddedServletContainerFactory
(never null
)protected Collection<ServletContextInitializer> getServletContextInitializerBeans()
ServletContextInitializer
s that should be used with the embedded
Servlet context. By default this method will first attempt to find
ServletContextInitializer
, Servlet
, Filter
and certain
EventListener
beans.protected void prepareEmbeddedWebApplicationContext(ServletContext servletContext)
WebApplicationContext
with the given fully loaded
ServletContext
. This method is usually called from
ServletContextInitializer.onStartup(ServletContext)
and is similar to the
functionality usually provided by a ContextLoaderListener
.servletContext
- the operational servlet contextprotected Resource getResourceByPath(String path)
getResourceByPath
in class GenericWebApplicationContext
public void setNamespace(String namespace)
setNamespace
in interface ConfigurableWebApplicationContext
setNamespace
in class GenericWebApplicationContext
public String getNamespace()
getNamespace
in interface ConfigurableWebApplicationContext
getNamespace
in class GenericWebApplicationContext
public void setServletConfig(ServletConfig servletConfig)
setServletConfig
in interface ConfigurableWebApplicationContext
setServletConfig
in class GenericWebApplicationContext
public ServletConfig getServletConfig()
getServletConfig
in interface ConfigurableWebApplicationContext
getServletConfig
in class GenericWebApplicationContext
public EmbeddedServletContainer getEmbeddedServletContainer()
EmbeddedServletContainer
that was created by the context or
null
if the container has not yet been created.Copyright © 2015 Pivotal Software, Inc.. All rights reserved.