Class TomcatWebServer
java.lang.Object
org.springframework.boot.web.embedded.tomcat.TomcatWebServer
- All Implemented Interfaces:
WebServer
WebServer
that can be used to control a Tomcat web server. Usually this class
should be created using the TomcatReactiveWebServerFactory
or
TomcatServletWebServerFactory
, but not directly.- Since:
- 2.0.0
-
Constructor Summary
ConstructorDescriptionTomcatWebServer
(org.apache.catalina.startup.Tomcat tomcat) Create a newTomcatWebServer
instance.TomcatWebServer
(org.apache.catalina.startup.Tomcat tomcat, boolean autoStart) Create a newTomcatWebServer
instance.TomcatWebServer
(org.apache.catalina.startup.Tomcat tomcat, boolean autoStart, Shutdown shutdown) Create a newTomcatWebServer
instance. -
Method Summary
Modifier and TypeMethodDescriptionint
getPort()
Return the port this server is listening on.org.apache.catalina.startup.Tomcat
Returns access to the underlying Tomcat server.void
shutDownGracefully
(GracefulShutdownCallback callback) Initiates a graceful shutdown of the web server.void
start()
Starts the web server.void
stop()
Stops the web server.
-
Constructor Details
-
TomcatWebServer
public TomcatWebServer(org.apache.catalina.startup.Tomcat tomcat) Create a newTomcatWebServer
instance.- Parameters:
tomcat
- the underlying Tomcat server
-
TomcatWebServer
public TomcatWebServer(org.apache.catalina.startup.Tomcat tomcat, boolean autoStart) Create a newTomcatWebServer
instance.- Parameters:
tomcat
- the underlying Tomcat serverautoStart
- if the server should be started
-
TomcatWebServer
public TomcatWebServer(org.apache.catalina.startup.Tomcat tomcat, boolean autoStart, Shutdown shutdown) Create a newTomcatWebServer
instance.- Parameters:
tomcat
- the underlying Tomcat serverautoStart
- if the server should be startedshutdown
- type of shutdown supported by the server- Since:
- 2.3.0
-
-
Method Details
-
start
Description copied from interface:WebServer
Starts the web server. Calling this method on an already started server has no effect.- Specified by:
start
in interfaceWebServer
- Throws:
WebServerException
- if the server cannot be started
-
stop
Description copied from interface:WebServer
Stops the web server. Calling this method on an already stopped server has no effect.- Specified by:
stop
in interfaceWebServer
- Throws:
WebServerException
- if the server cannot be stopped
-
getPort
public int getPort()Description copied from interface:WebServer
Return the port this server is listening on. -
getTomcat
public org.apache.catalina.startup.Tomcat getTomcat()Returns access to the underlying Tomcat server.- Returns:
- the Tomcat server
-
shutDownGracefully
Description copied from interface:WebServer
Initiates a graceful shutdown of the web server. Handling of new requests is prevented and the givencallback
is invoked at the end of the attempt. The attempt can be explicitly ended by invokingWebServer.stop()
. The default implementation invokes the callback immediately withGracefulShutdownResult.IMMEDIATE
, i.e. no attempt is made at a graceful shutdown.- Specified by:
shutDownGracefully
in interfaceWebServer
- Parameters:
callback
- the callback to invoke when the graceful shutdown completes
-