public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory implements ConfigurableTomcatWebServerFactory, ResourceLoaderAware
AbstractServletWebServerFactory
that can be used to create
TomcatWebServer
s. Can be initialized using Spring's
ServletContextInitializer
s or Tomcat LifecycleListener
s.
Unless explicitly configured otherwise this factory will create containers that listen for HTTP requests on port 8080.
AbstractConfigurableWebServerFactory.setPort(int)
,
setContextLifecycleListeners(Collection)
,
TomcatWebServer
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PROTOCOL
The class name of default protocol used.
|
logger
Constructor and Description |
---|
TomcatServletWebServerFactory()
Create a new
TomcatServletWebServerFactory instance. |
TomcatServletWebServerFactory(int port)
Create a new
TomcatServletWebServerFactory that listens for requests using
the specified port. |
TomcatServletWebServerFactory(String contextPath,
int port)
Create a new
TomcatServletWebServerFactory with the specified context path
and port. |
Modifier and Type | Method and Description |
---|---|
void |
addAdditionalTomcatConnectors(Connector... connectors)
Add
Connector s in addition to the default connector, e.g. |
void |
addConnectorCustomizers(TomcatConnectorCustomizer... tomcatConnectorCustomizers)
Add
TomcatConnectorCustomizer s that should be added to the Tomcat
Connector . |
void |
addContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers)
Add
TomcatContextCustomizer s that should be added to the Tomcat
Context . |
void |
addContextLifecycleListeners(LifecycleListener... contextLifecycleListeners)
Add
LifecycleListener s that should be added to the Tomcat Context . |
void |
addContextValves(Valve... contextValves)
|
void |
addEngineValves(Valve... engineValves)
|
void |
addTldSkipPatterns(String... patterns)
Add patterns that match jars to ignore for TLD scanning.
|
protected void |
configureContext(Context context,
ServletContextInitializer[] initializers)
Configure the Tomcat
Context . |
protected void |
customizeConnector(Connector connector) |
List<Connector> |
getAdditionalTomcatConnectors()
Returns a mutable collection of the
Connector s that will be added to the
Tomcat. |
Collection<LifecycleListener> |
getContextLifecycleListeners()
Returns a mutable collection of the
LifecycleListener s that will be applied
to the Tomcat Context . |
Collection<Valve> |
getContextValves()
|
Collection<Valve> |
getEngineValves()
|
Set<String> |
getTldSkipPatterns()
Returns a mutable set of the patterns that match jars to ignore for TLD scanning.
|
Collection<TomcatConnectorCustomizer> |
getTomcatConnectorCustomizers()
Returns a mutable collection of the
TomcatConnectorCustomizer s that will be
applied to the Tomcat Connector . |
Collection<TomcatContextCustomizer> |
getTomcatContextCustomizers()
Returns a mutable collection of the
TomcatContextCustomizer s that will be
applied to the Tomcat Context . |
protected TomcatWebServer |
getTomcatWebServer(Tomcat tomcat)
Factory method called to create the
TomcatWebServer . |
Charset |
getUriEncoding()
Returns the character encoding to use for URL decoding.
|
WebServer |
getWebServer(ServletContextInitializer... initializers)
Gets a new fully configured but paused
WebServer instance. |
protected void |
postProcessContext(Context context)
Post process the Tomcat
Context before it's used with the Tomcat Server. |
protected void |
prepareContext(Host host,
ServletContextInitializer[] initializers) |
void |
setBackgroundProcessorDelay(int delay)
Sets the background processor delay in seconds.
|
void |
setBaseDirectory(File baseDirectory)
Set the Tomcat base directory.
|
void |
setContextLifecycleListeners(Collection<? extends LifecycleListener> contextLifecycleListeners)
Set
LifecycleListener s that should be applied to the Tomcat
Context . |
void |
setContextValves(Collection<? extends Valve> contextValves)
|
void |
setEngineValves(Collection<? extends Valve> engineValves)
|
void |
setProtocol(String protocol)
The Tomcat protocol to use when create the
Connector . |
void |
setResourceLoader(ResourceLoader resourceLoader) |
void |
setTldSkipPatterns(Collection<String> patterns)
Set the patterns that match jars to ignore for TLD scanning.
|
void |
setTomcatConnectorCustomizers(Collection<? extends TomcatConnectorCustomizer> tomcatConnectorCustomizers)
Set
TomcatConnectorCustomizer s that should be applied to the Tomcat
Connector . |
void |
setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers)
Set
TomcatContextCustomizer s that should be applied to the Tomcat
Context . |
void |
setUriEncoding(Charset uriEncoding)
Set the character encoding to use for URL decoding.
|
addInitializers, getContextPath, getDisplayName, getDocumentRoot, getInitParameters, getJsp, getLocaleCharsetMappings, getMimeMappings, getSession, getUrlsOfJarsWithMetaInfResources, getValidDocumentRoot, getValidSessionStoreDir, getValidSessionStoreDir, isRegisterDefaultServlet, mergeInitializers, setContextPath, setDisplayName, setDocumentRoot, setInitializers, setInitParameters, setJsp, setLocaleCharsetMappings, setMimeMappings, setRegisterDefaultServlet, setSession, shouldRegisterJspServlet
addErrorPages, createTempDir, getAddress, getCompression, getErrorPages, getHttp2, getPort, getServerHeader, getSsl, getSslStoreProvider, setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setSsl, setSslStoreProvider
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setSsl, setSslStoreProvider
addErrorPages
public static final String DEFAULT_PROTOCOL
public TomcatServletWebServerFactory()
TomcatServletWebServerFactory
instance.public TomcatServletWebServerFactory(int port)
TomcatServletWebServerFactory
that listens for requests using
the specified port.port
- the port to listen onpublic TomcatServletWebServerFactory(String contextPath, int port)
TomcatServletWebServerFactory
with the specified context path
and port.contextPath
- the root context pathport
- the port to listen onpublic WebServer getWebServer(ServletContextInitializer... initializers)
ServletWebServerFactory
WebServer
instance. Clients should
not be able to connect to the returned server until WebServer.start()
is
called (which happens when the ApplicationContext
has been fully
refreshed).getWebServer
in interface ServletWebServerFactory
initializers
- ServletContextInitializer
s that should be applied as
the server startsWebServer
WebServer.stop()
protected void prepareContext(Host host, ServletContextInitializer[] initializers)
protected void customizeConnector(Connector connector)
protected void configureContext(Context context, ServletContextInitializer[] initializers)
Context
.context
- the Tomcat contextinitializers
- initializers to applyprotected void postProcessContext(Context context)
Context
before it's used with the Tomcat Server.
Subclasses can override this method to apply additional processing to the
Context
.context
- the Tomcat Context
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat)
TomcatWebServer
. Subclasses can
override this method to return a different TomcatWebServer
or apply
additional processing to the Tomcat server.tomcat
- the Tomcat server.TomcatWebServer
instancepublic void setResourceLoader(ResourceLoader resourceLoader)
setResourceLoader
in interface ResourceLoaderAware
public void setBaseDirectory(File baseDirectory)
ConfigurableTomcatWebServerFactory
setBaseDirectory
in interface ConfigurableTomcatWebServerFactory
baseDirectory
- the tomcat base directorypublic Set<String> getTldSkipPatterns()
public void setTldSkipPatterns(Collection<String> patterns)
patterns
- the jar patterns to skip when scanning for TLDs etcpublic void addTldSkipPatterns(String... patterns)
patterns
- the additional jar patterns to skip when scanning for TLDs etcpublic void setProtocol(String protocol)
Connector
.protocol
- the protocolConnector.Connector(String)
public void setEngineValves(Collection<? extends Valve> engineValves)
Valve
s that should be applied to the Tomcat Engine
. Calling
this method will replace any existing valves.engineValves
- the valves to setpublic Collection<Valve> getEngineValves()
public void addEngineValves(Valve... engineValves)
ConfigurableTomcatWebServerFactory
addEngineValves
in interface ConfigurableTomcatWebServerFactory
engineValves
- the valves to addpublic void setContextValves(Collection<? extends Valve> contextValves)
Valve
s that should be applied to the Tomcat Context
. Calling
this method will replace any existing valves.contextValves
- the valves to setpublic Collection<Valve> getContextValves()
getEngineValves()
public void addContextValves(Valve... contextValves)
contextValves
- the valves to addpublic void setContextLifecycleListeners(Collection<? extends LifecycleListener> contextLifecycleListeners)
LifecycleListener
s that should be applied to the Tomcat
Context
. Calling this method will replace any existing listeners.contextLifecycleListeners
- the listeners to setpublic Collection<LifecycleListener> getContextLifecycleListeners()
LifecycleListener
s that will be applied
to the Tomcat Context
.public void addContextLifecycleListeners(LifecycleListener... contextLifecycleListeners)
LifecycleListener
s that should be added to the Tomcat Context
.contextLifecycleListeners
- the listeners to addpublic void setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers)
TomcatContextCustomizer
s that should be applied to the Tomcat
Context
. Calling this method will replace any existing customizers.tomcatContextCustomizers
- the customizers to setpublic Collection<TomcatContextCustomizer> getTomcatContextCustomizers()
TomcatContextCustomizer
s that will be
applied to the Tomcat Context
.public void addContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers)
ConfigurableTomcatWebServerFactory
TomcatContextCustomizer
s that should be added to the Tomcat
Context
.addContextCustomizers
in interface ConfigurableTomcatWebServerFactory
tomcatContextCustomizers
- the customizers to addpublic void setTomcatConnectorCustomizers(Collection<? extends TomcatConnectorCustomizer> tomcatConnectorCustomizers)
TomcatConnectorCustomizer
s that should be applied to the Tomcat
Connector
. Calling this method will replace any existing customizers.tomcatConnectorCustomizers
- the customizers to setpublic void addConnectorCustomizers(TomcatConnectorCustomizer... tomcatConnectorCustomizers)
ConfigurableTomcatWebServerFactory
TomcatConnectorCustomizer
s that should be added to the Tomcat
Connector
.addConnectorCustomizers
in interface ConfigurableTomcatWebServerFactory
tomcatConnectorCustomizers
- the customizers to addpublic Collection<TomcatConnectorCustomizer> getTomcatConnectorCustomizers()
TomcatConnectorCustomizer
s that will be
applied to the Tomcat Connector
.public void addAdditionalTomcatConnectors(Connector... connectors)
Connector
s in addition to the default connector, e.g. for SSL or AJPconnectors
- the connectors to addpublic List<Connector> getAdditionalTomcatConnectors()
Connector
s that will be added to the
Tomcat.public void setUriEncoding(Charset uriEncoding)
ConfigurableTomcatWebServerFactory
setUriEncoding
in interface ConfigurableTomcatWebServerFactory
uriEncoding
- the uri encoding to setpublic Charset getUriEncoding()
public void setBackgroundProcessorDelay(int delay)
ConfigurableTomcatWebServerFactory
setBackgroundProcessorDelay
in interface ConfigurableTomcatWebServerFactory
delay
- the delay in secondsCopyright © 2019 Pivotal Software, Inc.. All rights reserved.