This class offers the following functionality:
Subclasses must implement doService() to handle requests. Because this extends HttpServletBean rather than HttpServlet directly, bean properties are mapped onto it. Subclasses can override initFrameworkServlet() for custom initialization.
Regards a "contextClass" parameter at the servlet init-param level, falling back to the default context class (XmlWebApplicationContext) if not found. With the default FrameworkServlet, a context class needs to implement ConfigurableWebApplicationContext.
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 one of Spring's default ApplicationContext implementations. 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.
| Field Summary | |
|---|---|
| static Class |
Default context class for FrameworkServlet. |
| static String |
Suffix for WebApplicationContext namespaces. |
| static String |
Prefix for the ServletContext attribute for the WebApplicationContext. |
| Fields inherited from org.springframework.web.servletHttpServletBean |
|---|
| Constructor Summary |
|---|
|
No description provided. |
| Method Summary | |
|---|---|
| protected WebApplicationContext |
Instantiate the WebApplicationContext for this servlet, either a default XmlWebApplicationContext or a custom context class if set. |
| void |
Close the WebApplicationContext of this servlet. |
| protected void |
Delegate DELETE requests to processRequest/doService. |
| protected void |
Delegate GET requests to processRequest/doService. |
| protected void |
Delegate POST requests to processRequest/doService. |
| protected void |
Delegate PUT requests to processRequest/doService. |
| protected void |
Subclasses must implement this method to do the work of request handling, receiving a centralized callback for GET, POST, PUT and DELETE. |
| Class |
Return the custom context class. |
| String |
Return the explicit context config location, if any. |
| String |
Return the namespace for this servlet, falling back to default scheme if no custom namespace was set: e.g. |
| String |
Return the ServletContext attribute name for this servlet's WebApplicationContext. |
| protected String |
Determine the username for the given request. |
| WebApplicationContext |
Return this servlet's WebApplicationContext. |
| protected void |
This method will be invoked after any bean properties have been set and the WebApplicationContext has been loaded. |
| protected void |
Overridden method of HttpServletBean, invoked after any bean properties have been set. |
| protected WebApplicationContext |
Initialize and publish the WebApplicationContext for this servlet. |
| boolean |
Return whether to publish this servlet's context as a ServletContext attribute. |
| boolean |
Return whether this servlet should publish a RequestHandlerEvent at the end of each request. |
| protected void |
Process this request, publishing an event regardless of the outcome. |
| void |
Set a custom context class. |
| void |
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
| void |
Set a custom namespace for this servlet, to be used for building a default context config location. |
| void |
Set whether to publish this servlet's context as a ServletContext attribute, available to all objects in the web container. |
| void |
Set whether this servlet should publish a RequestHandlerEvent at the end of each request. |
| Methods inherited from javax.servletGenericServlet |
|---|
| Methods inherited from javax.servlet.httpHttpServlet |
|---|
| Methods inherited from org.springframework.web.servletHttpServletBean |
|---|
| Methods inherited from java.langObject |
|---|
| Methods inherited from javax.servletServlet |
|---|
| Methods inherited from javax.servletServletConfig |
|---|
public
void
destroy
(
)
Will also be invoked by HttpServlet's default implementation of doHead, with a NoBodyResponse that just captures the content length.
The contract is essentially the same as that for the commonly overridden
doGet or doPost methods of HttpServlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
public
boolean
isPublishContext
(
)
public
boolean
isPublishEvents
(
)
doService() template method.
public
void
setPublishContext
(
boolean
publishContext
)
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.
public
void
setPublishEvents
(
boolean
publishEvents
)