public class SpringServlet extends ServletContainer
This class extends ServletContainer
and initiates the
WebApplication
with a Spring-based IoCComponentProviderFactory
,
SpringComponentProviderFactory
, such that instances of resource and
provider classes declared and managed by Spring can be obtained.
Classes of Spring beans declared using XML-based configuration or auto-wire-based confguration will be automatically registered if such classes are root resource classes or provider classes. It is not necessary to provide initialization parameters for declaring classes in the web.xml unless a mixture of Spring-managed and Jersey-managed classes is required.
The servlet supports configuration of child applicationContexts,
see CONTEXT_CONFIG_LOCATION
.
ServletContainer.ContextInjectableProvider<T>
Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_CONFIG_LOCATION
The context configuration location initialization parameter for declaring
that a child context should be used for bean definitions.
|
APPLICATION_CONFIG_CLASS, FEATURE_FILTER_FORWARD_ON_404, GLASSFISH_DEFAULT_ERROR_PAGE_RESPONSE, JSP_TEMPLATES_BASE_PATH, PROPERTY_FILTER_CONTEXT_PATH, PROPERTY_WEB_PAGE_CONTENT_REGEX, RESOURCE_CONFIG_CLASS
Constructor and Description |
---|
SpringServlet() |
Modifier and Type | Method and Description |
---|---|
protected org.springframework.context.ConfigurableApplicationContext |
getChildContext(String contextConfigLocation)
Get the child application context.
|
protected org.springframework.context.ConfigurableApplicationContext |
getContext()
Get the application context.
|
protected org.springframework.context.ConfigurableApplicationContext |
getDefaultContext()
Get the default application context.
|
protected ResourceConfig |
getDefaultResourceConfig(Map<String,Object> props,
WebConfig webConfig)
Get the default resource configuration if one is not declared in the
web.xml.
|
protected void |
initiate(ResourceConfig rc,
WebApplication wa)
Initiate the
WebApplication . |
configure, configure, configure, create, destroy, doFilter, doFilter, getDefaultResourceConfig, getServletContext, getStaticContentPattern, getWebConfig, init, init, init, load, reload, service, service
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public static final String CONTEXT_CONFIG_LOCATION
The parameter name is the String "contextConfigLocation".
A parameter value is a reference to one more spring configuration files separated by commas, semicolons or whitespace. distinct locations separated by commas, semicolons or whitespace
If this parameter is absent then the default application context configuration is utilized.
protected ResourceConfig getDefaultResourceConfig(Map<String,Object> props, WebConfig webConfig) throws javax.servlet.ServletException
ServletContainer
This implementation returns an instance of WebAppResourceConfig
that scans in files and directories as declared by the
ClasspathResourceConfig.PROPERTY_CLASSPATH
if present, otherwise
in the "WEB-INF/lib" and "WEB-INF/classes" directories.
An inheriting class may override this method to supply a different default resource configuration implementation.
getDefaultResourceConfig
in class ServletContainer
props
- the properties to pass to the resource configuration.webConfig
- the web configuration.javax.servlet.ServletException
- in case there was an error while retrieving the default resource configprotected void initiate(ResourceConfig rc, WebApplication wa)
ServletContainer
WebApplication
.
This method will be called once at initiation and for each reload of the Web application.
An inheriting class may override this method to initiate the Web application with different parameters.
initiate
in class ServletContainer
rc
- the Resource configurationwa
- the Web applicationprotected org.springframework.context.ConfigurableApplicationContext getContext()
If the initialization parameter CONTEXT_CONFIG_LOCATION
is present then this method will invoke getChildContext(java.lang.String)
otherwise this method will invoke getDefaultContext()
.
protected org.springframework.context.ConfigurableApplicationContext getDefaultContext()
The default application context will be looked up from the servlet
context using WebApplicationContextUtils.getRequiredWebApplicationContext(javax.servlet.ServletContext)
.
protected org.springframework.context.ConfigurableApplicationContext getChildContext(String contextConfigLocation)
The child application context is created as a child of the default
application context obtained from getDefaultContext()
.
contextConfigLocation
- the location of the child application
context.Copyright © 2013 Oracle Corporation. All rights reserved.