Accepts an optional "contextInitializerClasses" servlet init-param that
specifies one or more ApplicationContextInitializer classes. The managed web application context will be
delegated to these initializers, allowing for additional programmatic configuration,
e.g. adding property sources or activating profiles against the context's
environment. See also ContextLoader which
supports a "contextInitializerClasses" context-param with identical semantics for
the "root" web application context.

Passes a "contextConfigLocation" servlet init-param to the context instance,
parsing it into potentially multiple file paths which can be separated by any
number of commas and spaces, like "test-servlet.xml, myServlet.xml".
If not explicitly specified, the context implementation is supposed to build a
default location from the namespace of the servlet.

Note: In case of multiple config locations, later bean definitions will
override ones defined in earlier loaded files, at least when using Spring's
default ApplicationContext implementation. This can be leveraged to
deliberately override certain bean definitions via an extra XML file.

The default namespace is "'servlet-name'-servlet", e.g. "test-servlet" for a
servlet-name "test" (leading to a "/WEB-INF/test-servlet.xml" default location
with XmlWebApplicationContext). The namespace can also be set explicitly via
the "namespace" servlet init-param.

As of Spring 3.1, FrameworkServlet may now be injected with a web
application context, rather than creating its own internally. This is useful in Servlet
3.0+ environments, which support programmatic registration of servlet instances. See
FrameworkServlet(WebApplicationContext) Javadoc for details.

SERVLET_CONTEXT_PREFIX

Prefix for the ServletContext attribute for the WebApplicationContext.
The completion is the servlet name.

Constructor Detail

FrameworkServlet

public FrameworkServlet()

Create a new FrameworkServlet that will create its own internal web
application context based on defaults and values provided through servlet
init-params. Typically used in Servlet 2.5 or earlier environments, where the only
option for servlet registration is through web.xml which requires the use
of a no-arg constructor.

Calling setContextClass(java.lang.Class<?>) (init-param 'contextClass') overrides the
default XmlWebApplicationContext and allows for specifying an alternative class,
such as AnnotationConfigWebApplicationContext.

FrameworkServlet

Create a new FrameworkServlet with the given web application context. This
constructor is useful in Servlet 3.0+ environments where instance-based registration
of servlets is possible through the ServletContext.addServlet(java.lang.String, java.lang.String) API.

Using this constructor indicates that the following properties / init-params
will be ignored:

The given web application context may or may not yet be refreshed. If it (a) is an implementation
of ConfigurableWebApplicationContext and (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

ServletContext and ServletConfig objects will be delegated to
the application context

If the context has already been refreshed or does not implement
ConfigurableWebApplicationContext, none of the above will occur under the
assumption that the user has performed these actions (or not) per his or her
specific needs.

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

public java.lang.String getContextConfigLocation()

Return the explicit context config location, if any.

setPublishContext

public void setPublishContext(boolean publishContext)

Set whether to publish this servlet's context as a ServletContext attribute,
available to all objects in the web container. Default is "true".

This is especially handy during testing, although it is debatable whether
it's good practice to let other application objects access the context this way.

setPublishEvents

public void setPublishEvents(boolean publishEvents)

Set whether this servlet should publish a ServletRequestHandledEvent at the end
of each request. Default is "true"; can be turned off for a slight performance
improvement, provided that no ApplicationListeners rely on such events.

setThreadContextInheritable

Set whether to expose the LocaleContext and RequestAttributes as inheritable
for child threads (using an InheritableThreadLocal).

Default is "false", to avoid side effects on spawned background threads.
Switch this to "true" to enable inheritance for custom child threads which
are spawned during request processing and only used for this request
(that is, ending after their initial task, without reuse of the thread).

WARNING: Do not use inheritance for child threads if you are
accessing a thread pool which is configured to potentially add new threads
on demand (e.g. a JDK ThreadPoolExecutor),
since this will expose the inherited context to such a pooled thread.

Turn this flag on if you prefer OPTIONS requests to go through the
regular dispatching chain, just like other HTTP requests. This usually
means that your controllers will receive those requests; make sure
that those endpoints are actually able to handle an OPTIONS request.

Note that HttpServlet's default OPTIONS processing will be applied
in any case if your controllers happen to not set the 'Allow' header
(as required for an OPTIONS response).

Default is "false", applying HttpServlet's
default behavior (i.e. reflecting the message received back to the client).

Turn this flag on if you prefer TRACE requests to go through the
regular dispatching chain, just like other HTTP requests. This usually
means that your controllers will receive those requests; make sure
that those endpoints are actually able to handle a TRACE request.

Note that HttpServlet's default TRACE processing will be applied
in any case if your controllers happen to not generate a response
of content type 'message/http' (as required for a TRACE response).

findWebApplicationContext

Retrieve a WebApplicationContext from the ServletContext
attribute with the configured name. The
WebApplicationContext must have already been loaded and stored in the
ServletContext before this servlet gets initialized (or invoked).

Subclasses may override this method to provide a different
WebApplicationContext retrieval strategy.

getWebApplicationContext

initFrameworkServlet

This method will be invoked after any bean properties have been set and
the WebApplicationContext has been loaded. The default implementation is empty;
subclasses may override this method to perform any initialization they require.

Throws:

javax.servlet.ServletException - in case of an initialization exception

refresh

public void refresh()

Refresh this servlet's application context, as well as the
dependent state of the servlet.