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
 TomcatWebServers. Can be initialized using Spring's
 ServletContextInitializers or Tomcat LifecycleListeners.
 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 SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a newTomcatServletWebServerFactoryinstance.TomcatServletWebServerFactory(int port) Create a newTomcatServletWebServerFactorythat listens for requests using the specified port.TomcatServletWebServerFactory(String contextPath, int port) Create a newTomcatServletWebServerFactorywith the specified context path and port.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAdditionalTomcatConnectors(Connector... connectors) AddConnectors in addition to the default connector, e.g.voidaddConnectorCustomizers(TomcatConnectorCustomizer... tomcatConnectorCustomizers) AddTomcatConnectorCustomizers that should be added to the TomcatConnector.voidaddContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers) AddTomcatContextCustomizers that should be added to the TomcatContext.voidaddContextLifecycleListeners(LifecycleListener... contextLifecycleListeners) AddLifecycleListeners that should be added to the TomcatContext.voidaddContextValves(Valve... contextValves) voidaddEngineValves(Valve... engineValves) voidaddProtocolHandlerCustomizers(TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) AddTomcatProtocolHandlerCustomizers that should be added to the TomcatConnector.voidaddTldSkipPatterns(String... patterns) Add patterns that match jars to ignore for TLD scanning.protected voidconfigureContext(Context context, ServletContextInitializer[] initializers) Configure the TomcatContext.protected voidcustomizeConnector(Connector connector) Returns a mutable collection of theConnectors that will be added to the Tomcat.Returns a mutable collection of theLifecycleListeners 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 theTomcatConnectorCustomizers that will be applied to the TomcatConnector.Returns a mutable collection of theTomcatContextCustomizers that will be applied to the TomcatContext.Returns a mutable collection of theTomcatProtocolHandlerCustomizers that will be applied to the TomcatConnector.protected TomcatWebServergetTomcatWebServer(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 pausedWebServerinstance.protected voidpostProcessContext(Context context) Post process the TomcatContextbefore it's used with the Tomcat Server.protected voidprepareContext(Host host, ServletContextInitializer[] initializers) voidsetBackgroundProcessorDelay(int delay) Sets the background processor delay in seconds.voidsetBaseDirectory(File baseDirectory) Set the Tomcat base directory.voidsetContextLifecycleListeners(Collection<? extends LifecycleListener> contextLifecycleListeners) SetLifecycleListeners that should be applied to the TomcatContext.voidsetContextValves(Collection<? extends Valve> contextValves) voidsetDisableMBeanRegistry(boolean disableMBeanRegistry) Set whether the factory should disable Tomcat's MBean registry prior to creating the server.voidsetEngineValves(Collection<? extends Valve> engineValves) voidsetProtocol(String protocol) The Tomcat protocol to use when create theConnector.voidsetResourceLoader(ResourceLoader resourceLoader) voidsetTldSkipPatterns(Collection<String> patterns) Set the patterns that match jars to ignore for TLD scanning.voidsetTomcatConnectorCustomizers(Collection<? extends TomcatConnectorCustomizer> tomcatConnectorCustomizers) SetTomcatConnectorCustomizers that should be applied to the TomcatConnector.voidsetTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers) SetTomcatContextCustomizers that should be applied to the TomcatContext.voidsetTomcatProtocolHandlerCustomizers(Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizer) SetTomcatProtocolHandlerCustomizers that should be applied to the TomcatConnector.voidsetUriEncoding(Charset uriEncoding) Set the character encoding to use for URL decoding.voidsetUseApr(boolean useApr) Whether to use APR.Methods inherited from class org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryaddCookieSameSiteSuppliers, 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, shouldRegisterJspServletMethods inherited from class org.springframework.boot.web.server.AbstractConfigurableWebServerFactoryaddErrorPages, createTempDir, getAddress, getCompression, getErrorPages, getHttp2, getPort, getServerHeader, getServerNameSslBundles, getShutdown, getSsl, getSslBundle, getSslBundles, setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslBundlesMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.boot.web.server.ConfigurableWebServerFactorysetAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslBundlesMethods inherited from interface org.springframework.boot.web.server.ErrorPageRegistryaddErrorPages
- 
Field Details- 
DEFAULT_PROTOCOLThe class name of default protocol used.- See Also:
 
 
- 
- 
Constructor Details- 
TomcatServletWebServerFactorypublic TomcatServletWebServerFactory()Create a newTomcatServletWebServerFactoryinstance.
- 
TomcatServletWebServerFactorypublic TomcatServletWebServerFactory(int port) Create a newTomcatServletWebServerFactorythat listens for requests using the specified port.- Parameters:
- port- the port to listen on
 
- 
TomcatServletWebServerFactoryCreate a newTomcatServletWebServerFactorywith the specified context path and port.- Parameters:
- contextPath- the root context path
- port- the port to listen on
 
 
- 
- 
Method Details- 
getWebServerDescription copied from interface:ServletWebServerFactoryGets a new fully configured but pausedWebServerinstance. Clients should not be able to connect to the returned server untilWebServer.start()is called (which happens when theApplicationContexthas been fully refreshed).- Specified by:
- getWebServerin interface- ServletWebServerFactory
- Parameters:
- initializers-- ServletContextInitializers that should be applied as the server starts
- Returns:
- a fully configured and started WebServer
- See Also:
 
- 
prepareContext
- 
customizeConnector
- 
configureContextConfigure the TomcatContext.- Parameters:
- context- the Tomcat context
- initializers- initializers to apply
 
- 
postProcessContextPost process the TomcatContextbefore it's used with the Tomcat Server. Subclasses can override this method to apply additional processing to theContext.- Parameters:
- context- the Tomcat- Context
 
- 
getTomcatWebServerFactory method called to create theTomcatWebServer. Subclasses can override this method to return a differentTomcatWebServeror apply additional processing to the Tomcat server.- Parameters:
- tomcat- the Tomcat server.
- Returns:
- a new TomcatWebServerinstance
 
- 
setResourceLoader- Specified by:
- setResourceLoaderin interface- ResourceLoaderAware
 
- 
setBaseDirectoryDescription copied from interface:ConfigurableTomcatWebServerFactorySet the Tomcat base directory. If not specified a temporary directory will be used.- Specified by:
- setBaseDirectoryin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- baseDirectory- the tomcat base directory
 
- 
getTldSkipPatternsReturns a mutable set of the patterns that match jars to ignore for TLD scanning.- Returns:
- the set of jars to ignore for TLD scanning
 
- 
setTldSkipPatternsSet 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
 
- 
addTldSkipPatternsAdd 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
 
- 
setProtocolThe Tomcat protocol to use when create theConnector.- Parameters:
- protocol- the protocol
- See Also:
 
- 
setEngineValvesSetValves 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
 
- 
addEngineValvesDescription copied from interface:ConfigurableTomcatWebServerFactory- Specified by:
- addEngineValvesin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- engineValves- the valves to add
 
- 
setContextValvesSetValves 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
 
- 
setContextLifecycleListenerspublic void setContextLifecycleListeners(Collection<? extends LifecycleListener> contextLifecycleListeners) SetLifecycleListeners that should be applied to the TomcatContext. Calling this method will replace any existing listeners.- Parameters:
- contextLifecycleListeners- the listeners to set
 
- 
getContextLifecycleListenersReturns a mutable collection of theLifecycleListeners that will be applied to the TomcatContext.- Returns:
- the context lifecycle listeners that will be applied
 
- 
addContextLifecycleListenersAddLifecycleListeners that should be added to the TomcatContext.- Parameters:
- contextLifecycleListeners- the listeners to add
 
- 
setTomcatContextCustomizerspublic void setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers) SetTomcatContextCustomizers that should be applied to the TomcatContext. Calling this method will replace any existing customizers.- Parameters:
- tomcatContextCustomizers- the customizers to set
 
- 
getTomcatContextCustomizersReturns a mutable collection of theTomcatContextCustomizers that will be applied to the TomcatContext.- Returns:
- the listeners that will be applied
 
- 
addContextCustomizersDescription copied from interface:ConfigurableTomcatWebServerFactoryAddTomcatContextCustomizers that should be added to the TomcatContext.- Specified by:
- addContextCustomizersin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- tomcatContextCustomizers- the customizers to add
 
- 
setTomcatConnectorCustomizerspublic void setTomcatConnectorCustomizers(Collection<? extends TomcatConnectorCustomizer> tomcatConnectorCustomizers) SetTomcatConnectorCustomizers that should be applied to the TomcatConnector. Calling this method will replace any existing customizers.- Parameters:
- tomcatConnectorCustomizers- the customizers to set
 
- 
addConnectorCustomizersDescription copied from interface:ConfigurableTomcatWebServerFactoryAddTomcatConnectorCustomizers that should be added to the TomcatConnector.- Specified by:
- addConnectorCustomizersin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- tomcatConnectorCustomizers- the customizers to add
 
- 
getTomcatConnectorCustomizersReturns a mutable collection of theTomcatConnectorCustomizers that will be applied to the TomcatConnector.- Returns:
- the customizers that will be applied
 
- 
setTomcatProtocolHandlerCustomizerspublic void setTomcatProtocolHandlerCustomizers(Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizer) SetTomcatProtocolHandlerCustomizers 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
 
- 
addProtocolHandlerCustomizerspublic void addProtocolHandlerCustomizers(TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) AddTomcatProtocolHandlerCustomizers that should be added to the TomcatConnector.- Specified by:
- addProtocolHandlerCustomizersin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- tomcatProtocolHandlerCustomizers- the customizers to add
- Since:
- 2.2.0
 
- 
getTomcatProtocolHandlerCustomizersReturns a mutable collection of theTomcatProtocolHandlerCustomizers that will be applied to the TomcatConnector.- Returns:
- the customizers that will be applied
- Since:
- 2.2.0
 
- 
addAdditionalTomcatConnectorsAddConnectors in addition to the default connector, e.g. for SSL or AJP.Connector customizersare not applied to connectors added this way.- Parameters:
- connectors- the connectors to add
 
- 
getAdditionalTomcatConnectorsReturns a mutable collection of theConnectors that will be added to the Tomcat.- Returns:
- the additionalTomcatConnectors
 
- 
setUriEncodingDescription copied from interface:ConfigurableTomcatWebServerFactorySet the character encoding to use for URL decoding. If not specified 'UTF-8' will be used.- Specified by:
- setUriEncodingin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- uriEncoding- the uri encoding to set
 
- 
getUriEncodingReturns the character encoding to use for URL decoding.- Returns:
- the URI encoding
 
- 
setBackgroundProcessorDelaypublic void setBackgroundProcessorDelay(int delay) Description copied from interface:ConfigurableTomcatWebServerFactorySets the background processor delay in seconds.- Specified by:
- setBackgroundProcessorDelayin interface- ConfigurableTomcatWebServerFactory
- Parameters:
- delay- the delay in seconds
 
- 
setDisableMBeanRegistrypublic 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
 
- 
setUseAprpublic void setUseApr(boolean useApr) Whether to use APR.- Parameters:
- useApr- whether to use APR
- Since:
- 3.4.4
 
 
-