spring-framework / org.springframework.web.context.support

Package org.springframework.web.context.support

Types

AnnotationConfigWebApplicationContext

open class AnnotationConfigWebApplicationContext : AbstractRefreshableWebApplicationContext, AnnotationConfigRegistry

org.springframework.web.context.WebApplicationContext implementation which accepts annotated classes as input - in particular org.springframework.context.annotation.Configuration-annotated classes, but also plain org.springframework.stereotype.Component classes and JSR-330 compliant classes using javax.inject annotations. Allows for registering classes one by one (specifying class names as config location) as well as for classpath scanning (specifying base packages as config location).

This is essentially the equivalent of org.springframework.context.annotation.AnnotationConfigApplicationContext for a web environment.

To make use of this application context, the "contextClass" context-param for ContextLoader and/or "contextClass" init-param for FrameworkServlet must be set to the fully-qualified name of this class.

As of Spring 3.1, this class may also be directly instantiated and injected into Spring's DispatcherServlet or ContextLoaderListener when using the new org.springframework.web.WebApplicationInitializer code-based alternative to web.xml. See its Javadoc for details and usage examples.

Unlike XmlWebApplicationContext, no default configuration class locations are assumed. Rather, it is a requirement to set the "contextConfigLocation" context-param for ContextLoader and/or "contextConfigLocation" init-param for FrameworkServlet. The param-value may contain both fully-qualified class names and base packages to scan for components. See #loadBeanDefinitions for exact details on how these locations are processed.

As an alternative to setting the "contextConfigLocation" parameter, users may implement an org.springframework.context.ApplicationContextInitializer and set the "contextInitializerClasses" context-param / init-param. In such cases, users should favor the #refresh() and #scan(String...) methods over the #setConfigLocation(String) method, which is primarily for use by ContextLoader.

Note: In case of multiple @Configuration classes, later @Bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra Configuration class.

ContextExposingHttpServletRequest

open class ContextExposingHttpServletRequest : HttpServletRequestWrapper

HttpServletRequest decorator that makes all Spring beans in a given WebApplicationContext accessible as request attributes, through lazy checking once an attribute gets accessed.

GroovyWebApplicationContext

open class GroovyWebApplicationContext : AbstractRefreshableWebApplicationContext, GroovyObject

org.springframework.web.context.WebApplicationContext implementation which takes its configuration from Groovy bean definition scripts and/or XML files, as understood by an org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader. This is essentially the equivalent of org.springframework.context.support.GenericGroovyApplicationContext for a web environment.

By default, the configuration will be taken from "/WEB-INF/applicationContext.groovy" for the root context, and "/WEB-INF/test-servlet.groovy" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

The config location defaults can be overridden via the "contextConfigLocation" context-param of org.springframework.web.context.ContextLoader and servlet init-param of org.springframework.web.servlet.FrameworkServlet. Config locations can either denote concrete files like "/WEB-INF/context.groovy" or Ant-style patterns like "/WEB-INF/*-context.groovy" (see org.springframework.util.PathMatcher javadoc for pattern details). Note that ".xml" files will be parsed as XML content; all other kinds of resources will be parsed as Groovy scripts.

Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra Groovy script.

For a WebApplicationContext that reads in a different bean definition format, create an analogous subclass of AbstractRefreshableWebApplicationContext. Such a context implementation can be specified as "contextClass" context-param for ContextLoader or "contextClass" init-param for FrameworkServlet.

HttpRequestHandlerServlet

open class HttpRequestHandlerServlet : HttpServlet

Simple HttpServlet that delegates to an HttpRequestHandler bean defined in Spring's root web application context. The target bean name must match the HttpRequestHandlerServlet servlet-name as defined in web.xml.

This can for example be used to expose a single Spring remote exporter, such as org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter or org.springframework.remoting.caucho.HessianServiceExporter, per HttpRequestHandlerServlet definition. This is a minimal alternative to defining remote exporters as beans in a DispatcherServlet context (with advanced mapping and interception facilities being available there).

LiveBeansViewServlet

open class LiveBeansViewServlet : HttpServlet

Servlet variant of LiveBeansView's MBean exposure.

Generates a JSON snapshot for current beans and their dependencies in all ApplicationContexts that live within the current web application.

RequestHandledEvent

open class RequestHandledEvent : ApplicationEvent

Event raised when a request is handled within an ApplicationContext.

Supported by Spring's own FrameworkServlet (through a specific ServletRequestHandledEvent subclass), but can also be raised by any other web component. Used, for example, by Spring's out-of-the-box PerformanceMonitorListener.

ServletConfigPropertySource

open class ServletConfigPropertySource : EnumerablePropertySource<ServletConfig>

PropertySource that reads init parameters from a ServletConfig object.

ServletContextAttributeExporter

open class ServletContextAttributeExporter : ServletContextAware

Exporter that takes Spring-defined objects and exposes them as ServletContext attributes. Usually, bean references will be used to export Spring-defined beans as ServletContext attributes.

Useful to make Spring-defined beans available to code that is not aware of Spring at all, but rather just of the Servlet API. Client code can then use plain ServletContext attribute lookups to access those objects, despite them being defined in a Spring application context.

Alternatively, consider using the WebApplicationContextUtils class to access Spring-defined beans via the WebApplicationContext interface. This makes client code aware of Spring API, of course.

ServletContextAttributeFactoryBean

open class ServletContextAttributeFactoryBean : FactoryBean<Any>, ServletContextAware

FactoryBean that fetches a specific, existing ServletContext attribute. Exposes that ServletContext attribute when used as bean reference, effectively making it available as named Spring bean instance.

Intended to link in ServletContext attributes that exist before the startup of the Spring application context. Typically, such attributes will have been put there by third-party web frameworks. In a purely Spring-based web application, no such linking in of ServletContext attributes will be necessary.

NOTE: As of Spring 3.0, you may also use the "contextAttributes" default bean which is of type Map, and dereference it using an "#{contextAttributes.myKey}" expression to access a specific attribute by name.

ServletContextAwareProcessor

open class ServletContextAwareProcessor : BeanPostProcessor

org.springframework.beans.factory.config.BeanPostProcessor implementation that passes the ServletContext to beans that implement the ServletContextAware interface.

Web application contexts will automatically register this with their underlying bean factory. Applications do not use this directly.

ServletContextLiveBeansView

open class ServletContextLiveBeansView : LiveBeansView

LiveBeansView subclass which looks for all ApplicationContexts in the web application, as exposed in ServletContext attributes.

ServletContextParameterFactoryBean

open class ServletContextParameterFactoryBean : FactoryBean<String>, ServletContextAware

FactoryBean that retrieves a specific ServletContext init parameter (that is, a "context-param" defined in web.xml). Exposes that ServletContext init parameter when used as bean reference, effectively making it available as named Spring bean instance.

NOTE: As of Spring 3.0, you may also use the "contextParameters" default bean which is of type Map, and dereference it using an "#{contextParameters.myKey}" expression to access a specific parameter by name.

ServletContextPropertySource

open class ServletContextPropertySource : EnumerablePropertySource<ServletContext>

PropertySource that reads init parameters from a ServletContext object.

ServletContextResource

open class ServletContextResource : AbstractFileResolvingResource, ContextResource

org.springframework.core.io.Resource implementation for javax.servlet.ServletContext resources, interpreting relative paths within the web application root directory.

Always supports stream access and URL access, but only allows java.io.File access when the web application archive is expanded.

ServletContextResourceLoader

open class ServletContextResourceLoader : DefaultResourceLoader

ResourceLoader implementation that resolves paths as ServletContext resources, for use outside a WebApplicationContext (for example, in an HttpServletBean or GenericFilterBean subclass).

Within a WebApplicationContext, resource paths are automatically resolved as ServletContext resources by the context implementation.

ServletContextResourcePatternResolver

open class ServletContextResourcePatternResolver : PathMatchingResourcePatternResolver

ServletContext-aware subclass of PathMatchingResourcePatternResolver, able to find matching resources below the web application root directory via ServletContext#getResourcePaths. Falls back to the superclass' file system checking for other resources.

ServletContextScope

open class ServletContextScope : Scope, DisposableBean

Scope wrapper for a ServletContext, i.e. for global web application attributes.

This differs from traditional Spring singletons in that it exposes attributes in the ServletContext. Those attributes will get destroyed whenever the entire application shuts down, which might be earlier or later than the shutdown of the containing Spring ApplicationContext.

The associated destruction mechanism relies on a org.springframework.web.context.ContextCleanupListener being registered in web.xml. Note that org.springframework.web.context.ContextLoaderListener includes ContextCleanupListener's functionality.

This scope is registered as default scope with key "application".

ServletRequestHandledEvent

open class ServletRequestHandledEvent : RequestHandledEvent

Servlet-specific subclass of RequestHandledEvent, adding servlet-specific context information.

SpringBeanAutowiringSupport

abstract class SpringBeanAutowiringSupport

Convenient base class for self-autowiring classes that gets constructed within a Spring-based web application. Resolves @Autowired annotations in the endpoint class against beans in the current Spring root web application context (as determined by the current thread's context ClassLoader, which needs to be the web application's ClassLoader). Can alternatively be used as a delegate instead of as a base class.

A typical usage of this base class is a JAX-WS endpoint class: Such a Spring-based JAX-WS endpoint implementation will follow the standard JAX-WS contract for endpoint classes but will be 'thin' in that it delegates the actual work to one or more Spring-managed service beans - typically obtained using @Autowired. The lifecycle of such an endpoint instance will be managed by the JAX-WS runtime, hence the need for this base class to provide @Autowired processing based on the current Spring context.

NOTE: If there is an explicit way to access the ServletContext, prefer such a way over using this class. The WebApplicationContextUtils class allows for easy access to the Spring root web application context based on the ServletContext.

StandardServletEnvironment

open class StandardServletEnvironment : StandardEnvironment, ConfigurableWebEnvironment

Environment implementation to be used by Servlet-based web applications. All web-related (servlet-based) ApplicationContext classes initialize an instance by default.

Contributes ServletConfig, ServletContext, and JNDI-based PropertySource instances. See #customizePropertySources method documentation for details.

StaticWebApplicationContext

open class StaticWebApplicationContext : StaticApplicationContext, ConfigurableWebApplicationContext, ThemeSource

Static org.springframework.web.context.WebApplicationContext implementation for testing. Not intended for use in production applications.

Implements the org.springframework.web.context.ConfigurableWebApplicationContext interface to allow for direct replacement of an XmlWebApplicationContext, despite not actually supporting external configuration files.

Interprets resource paths as servlet context resources, i.e. as paths beneath the web application root. Absolute paths, e.g. for files outside the web app root, can be accessed via "file:" URLs, as implemented by org.springframework.core.io.DefaultResourceLoader.

In addition to the special beans detected by org.springframework.context.support.AbstractApplicationContext, this class detects a bean of type org.springframework.ui.context.ThemeSource in the context, under the special bean name "themeSource".

WebApplicationContextUtils

abstract class WebApplicationContextUtils

Convenience methods for retrieving the root WebApplicationContext for a given ServletContext. This is useful for programmatically accessing a Spring application context from within custom web views or MVC actions.

Note that there are more convenient ways of accessing the root context for many web frameworks, either part of Spring or available as an external library. This helper class is just the most generic way to access the root context.

XmlWebApplicationContext

open class XmlWebApplicationContext : AbstractRefreshableWebApplicationContext

org.springframework.web.context.WebApplicationContext implementation which takes its configuration from XML documents, understood by an org.springframework.beans.factory.xml.XmlBeanDefinitionReader. This is essentially the equivalent of org.springframework.context.support.GenericXmlApplicationContext for a web environment.

By default, the configuration will be taken from "/WEB-INF/applicationContext.xml" for the root context, and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

The config location defaults can be overridden via the "contextConfigLocation" context-param of org.springframework.web.context.ContextLoader and servlet init-param of org.springframework.web.servlet.FrameworkServlet. Config locations can either denote concrete files like "/WEB-INF/context.xml" or Ant-style patterns like "/WEB-INF/*-context.xml" (see org.springframework.util.PathMatcher javadoc for pattern details).

Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra XML file.

For a WebApplicationContext that reads in a different bean definition format, create an analogous subclass of AbstractRefreshableWebApplicationContext. Such a context implementation can be specified as "contextClass" context-param for ContextLoader or "contextClass" init-param for FrameworkServlet.