Class TomcatServletWebServerFactory
java.lang.Object
org.springframework.boot.web.server.AbstractConfigurableWebServerFactory
org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
- All Implemented Interfaces:
Aware
,ConfigurableTomcatWebServerFactory
,ConfigurableWebServerFactory
,ErrorPageRegistry
,WebServerFactory
,ConfigurableServletWebServerFactory
,ServletWebServerFactory
,WebListenerRegistry
,ResourceLoaderAware
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.
- Since:
- 2.0.0
- Author:
- Phillip Webb, Dave Syer, Brock Mills, Stephane Nicoll, Andy Wilkinson, EddĂș MelĂ©ndez, Christoffer Sawicki, Dawid Antecki, Moritz Halbritter, Scott Frederick
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a newTomcatServletWebServerFactory
instance.TomcatServletWebServerFactory
(int port) Create a newTomcatServletWebServerFactory
that listens for requests using the specified port.TomcatServletWebServerFactory
(String contextPath, int port) Create a newTomcatServletWebServerFactory
with the specified context path and port. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAdditionalTomcatConnectors
(Connector... connectors) AddConnector
s in addition to the default connector, e.g.void
addConnectorCustomizers
(TomcatConnectorCustomizer... tomcatConnectorCustomizers) AddTomcatConnectorCustomizer
s that should be added to the TomcatConnector
.void
addContextCustomizers
(TomcatContextCustomizer... tomcatContextCustomizers) AddTomcatContextCustomizer
s that should be added to the TomcatContext
.void
addContextLifecycleListeners
(LifecycleListener... contextLifecycleListeners) AddLifecycleListener
s that should be added to the TomcatContext
.void
addContextValves
(Valve... contextValves) void
addEngineValves
(Valve... engineValves) void
addProtocolHandlerCustomizers
(TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) AddTomcatProtocolHandlerCustomizer
s that should be added to the TomcatConnector
.void
addTldSkipPatterns
(String... patterns) Add patterns that match jars to ignore for TLD scanning.protected void
configureContext
(Context context, ServletContextInitializer[] initializers) Configure the TomcatContext
.protected void
customizeConnector
(Connector connector) Returns a mutable collection of theConnector
s that will be added to the Tomcat.Returns a mutable collection of theLifecycleListener
s that will be applied to the TomcatContext
.Returns a mutable set of the patterns that match jars to ignore for TLD scanning.Returns a mutable collection of theTomcatConnectorCustomizer
s that will be applied to the TomcatConnector
.Returns a mutable collection of theTomcatContextCustomizer
s that will be applied to the TomcatContext
.Returns a mutable collection of theTomcatProtocolHandlerCustomizer
s that will be applied to the TomcatConnector
.protected TomcatWebServer
getTomcatWebServer
(Tomcat tomcat) Factory method called to create theTomcatWebServer
.Returns the character encoding to use for URL decoding.getWebServer
(ServletContextInitializer... initializers) Gets a new fully configured but pausedWebServer
instance.protected void
postProcessContext
(Context context) Post process the TomcatContext
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) SetLifecycleListener
s that should be applied to the TomcatContext
.void
setContextValves
(Collection<? extends Valve> contextValves) void
setDisableMBeanRegistry
(boolean disableMBeanRegistry) Set whether the factory should disable Tomcat's MBean registry prior to creating the server.void
setEngineValves
(Collection<? extends Valve> engineValves) void
setProtocol
(String protocol) The Tomcat protocol to use when create theConnector
.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) SetTomcatConnectorCustomizer
s that should be applied to the TomcatConnector
.void
setTomcatContextCustomizers
(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers) SetTomcatContextCustomizer
s that should be applied to the TomcatContext
.void
setTomcatProtocolHandlerCustomizers
(Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizer) SetTomcatProtocolHandlerCustomizer
s that should be applied to the TomcatConnector
.void
setUriEncoding
(Charset uriEncoding) Set the character encoding to use for URL decoding.Methods inherited from class org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory
addCookieSameSiteSuppliers, addInitializers, addMimeMappings, addWebListeners, getContextPath, getCookieSameSiteSuppliers, getDisplayName, getDocumentRoot, getInitParameters, getJsp, getLocaleCharsetMappings, getMimeMappings, getSession, getUrlsOfJarsWithMetaInfResources, getValidDocumentRoot, getValidSessionStoreDir, getValidSessionStoreDir, getWebListenerClassNames, isRegisterDefaultServlet, mergeInitializers, setContextPath, setCookieSameSiteSuppliers, setDisplayName, setDocumentRoot, setInitializers, setInitParameters, setJsp, setLocaleCharsetMappings, setMimeMappings, setRegisterDefaultServlet, setSession, shouldRegisterJspServlet
Methods inherited from class org.springframework.boot.web.server.AbstractConfigurableWebServerFactory
addErrorPages, createTempDir, getAddress, getCompression, getErrorPages, getHttp2, getPort, getServerHeader, getServerNameSslBundles, getShutdown, getSsl, getSslBundle, getSslBundles, setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslBundles
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.boot.web.server.ConfigurableWebServerFactory
setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslBundles
Methods inherited from interface org.springframework.boot.web.server.ErrorPageRegistry
addErrorPages
-
Field Details
-
DEFAULT_PROTOCOL
The class name of default protocol used.- See Also:
-
-
Constructor Details
-
TomcatServletWebServerFactory
public TomcatServletWebServerFactory()Create a newTomcatServletWebServerFactory
instance. -
TomcatServletWebServerFactory
public TomcatServletWebServerFactory(int port) Create a newTomcatServletWebServerFactory
that listens for requests using the specified port.- Parameters:
port
- the port to listen on
-
TomcatServletWebServerFactory
Create a newTomcatServletWebServerFactory
with the specified context path and port.- Parameters:
contextPath
- the root context pathport
- the port to listen on
-
-
Method Details
-
getWebServer
Description copied from interface:ServletWebServerFactory
Gets a new fully configured but pausedWebServer
instance. Clients should not be able to connect to the returned server untilWebServer.start()
is called (which happens when theApplicationContext
has been fully refreshed).- Specified by:
getWebServer
in interfaceServletWebServerFactory
- Parameters:
initializers
-ServletContextInitializer
s that should be applied as the server starts- Returns:
- a fully configured and started
WebServer
- See Also:
-
prepareContext
-
customizeConnector
-
configureContext
Configure the TomcatContext
.- Parameters:
context
- the Tomcat contextinitializers
- initializers to apply
-
postProcessContext
Post process the TomcatContext
before it's used with the Tomcat Server. Subclasses can override this method to apply additional processing to theContext
.- Parameters:
context
- the TomcatContext
-
getTomcatWebServer
Factory method called to create theTomcatWebServer
. Subclasses can override this method to return a differentTomcatWebServer
or apply additional processing to the Tomcat server.- Parameters:
tomcat
- the Tomcat server.- Returns:
- a new
TomcatWebServer
instance
-
setResourceLoader
- Specified by:
setResourceLoader
in interfaceResourceLoaderAware
-
setBaseDirectory
Description copied from interface:ConfigurableTomcatWebServerFactory
Set the Tomcat base directory. If not specified a temporary directory will be used.- Specified by:
setBaseDirectory
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
baseDirectory
- the tomcat base directory
-
getTldSkipPatterns
Returns a mutable set of the patterns that match jars to ignore for TLD scanning.- Returns:
- the list of jars to ignore for TLD scanning
-
setTldSkipPatterns
Set the patterns that match jars to ignore for TLD scanning. See Tomcat's catalina.properties for typical values. Defaults to a list drawn from that source.- Parameters:
patterns
- the jar patterns to skip when scanning for TLDs etc
-
addTldSkipPatterns
Add patterns that match jars to ignore for TLD scanning. See Tomcat's catalina.properties for typical values.- Parameters:
patterns
- the additional jar patterns to skip when scanning for TLDs etc
-
setProtocol
The Tomcat protocol to use when create theConnector
.- Parameters:
protocol
- the protocol- See Also:
-
setEngineValves
SetValve
s that should be applied to the TomcatEngine
. Calling this method will replace any existing valves.- Parameters:
engineValves
- the valves to set
-
getEngineValves
- Returns:
- the engine valves that will be applied
-
addEngineValves
Description copied from interface:ConfigurableTomcatWebServerFactory
- Specified by:
addEngineValves
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
engineValves
- the valves to add
-
setContextValves
SetValve
s that should be applied to the TomcatContext
. Calling this method will replace any existing valves.- Parameters:
contextValves
- the valves to set
-
getContextValves
- Returns:
- the context valves that will be applied
- See Also:
-
addContextValves
- Parameters:
contextValves
- the valves to add
-
setContextLifecycleListeners
public void setContextLifecycleListeners(Collection<? extends LifecycleListener> contextLifecycleListeners) SetLifecycleListener
s that should be applied to the TomcatContext
. Calling this method will replace any existing listeners.- Parameters:
contextLifecycleListeners
- the listeners to set
-
getContextLifecycleListeners
Returns a mutable collection of theLifecycleListener
s that will be applied to the TomcatContext
.- Returns:
- the context lifecycle listeners that will be applied
-
addContextLifecycleListeners
AddLifecycleListener
s that should be added to the TomcatContext
.- Parameters:
contextLifecycleListeners
- the listeners to add
-
setTomcatContextCustomizers
public void setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers) SetTomcatContextCustomizer
s that should be applied to the TomcatContext
. Calling this method will replace any existing customizers.- Parameters:
tomcatContextCustomizers
- the customizers to set
-
getTomcatContextCustomizers
Returns a mutable collection of theTomcatContextCustomizer
s that will be applied to the TomcatContext
.- Returns:
- the listeners that will be applied
-
addContextCustomizers
Description copied from interface:ConfigurableTomcatWebServerFactory
AddTomcatContextCustomizer
s that should be added to the TomcatContext
.- Specified by:
addContextCustomizers
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
tomcatContextCustomizers
- the customizers to add
-
setTomcatConnectorCustomizers
public void setTomcatConnectorCustomizers(Collection<? extends TomcatConnectorCustomizer> tomcatConnectorCustomizers) SetTomcatConnectorCustomizer
s that should be applied to the TomcatConnector
. Calling this method will replace any existing customizers.- Parameters:
tomcatConnectorCustomizers
- the customizers to set
-
addConnectorCustomizers
Description copied from interface:ConfigurableTomcatWebServerFactory
AddTomcatConnectorCustomizer
s that should be added to the TomcatConnector
.- Specified by:
addConnectorCustomizers
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
tomcatConnectorCustomizers
- the customizers to add
-
getTomcatConnectorCustomizers
Returns a mutable collection of theTomcatConnectorCustomizer
s that will be applied to the TomcatConnector
.- Returns:
- the customizers that will be applied
-
setTomcatProtocolHandlerCustomizers
public void setTomcatProtocolHandlerCustomizers(Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizer) SetTomcatProtocolHandlerCustomizer
s that should be applied to the TomcatConnector
. Calling this method will replace any existing customizers.- Parameters:
tomcatProtocolHandlerCustomizer
- the customizers to set- Since:
- 2.2.0
-
addProtocolHandlerCustomizers
public void addProtocolHandlerCustomizers(TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) AddTomcatProtocolHandlerCustomizer
s that should be added to the TomcatConnector
.- Specified by:
addProtocolHandlerCustomizers
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
tomcatProtocolHandlerCustomizers
- the customizers to add- Since:
- 2.2.0
-
getTomcatProtocolHandlerCustomizers
Returns a mutable collection of theTomcatProtocolHandlerCustomizer
s that will be applied to the TomcatConnector
.- Returns:
- the customizers that will be applied
- Since:
- 2.2.0
-
addAdditionalTomcatConnectors
AddConnector
s in addition to the default connector, e.g. for SSL or AJP.Connector customizers
are not applied to connectors added this way.- Parameters:
connectors
- the connectors to add
-
getAdditionalTomcatConnectors
Returns a mutable collection of theConnector
s that will be added to the Tomcat.- Returns:
- the additionalTomcatConnectors
-
setUriEncoding
Description copied from interface:ConfigurableTomcatWebServerFactory
Set the character encoding to use for URL decoding. If not specified 'UTF-8' will be used.- Specified by:
setUriEncoding
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
uriEncoding
- the uri encoding to set
-
getUriEncoding
Returns the character encoding to use for URL decoding.- Returns:
- the URI encoding
-
setBackgroundProcessorDelay
public void setBackgroundProcessorDelay(int delay) Description copied from interface:ConfigurableTomcatWebServerFactory
Sets the background processor delay in seconds.- Specified by:
setBackgroundProcessorDelay
in interfaceConfigurableTomcatWebServerFactory
- Parameters:
delay
- the delay in seconds
-
setDisableMBeanRegistry
public void setDisableMBeanRegistry(boolean disableMBeanRegistry) Set whether the factory should disable Tomcat's MBean registry prior to creating the server.- Parameters:
disableMBeanRegistry
- whether to disable the MBean registry- Since:
- 2.2.0
-