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
- Author:
- Brian Clozel, Kristine Jetzke
-
Constructor Summary
ConstructorDescriptionTomcatWebServer
(Tomcat tomcat) Create a newTomcatWebServer
instance.TomcatWebServer
(Tomcat tomcat, boolean autoStart) Create a newTomcatWebServer
instance.TomcatWebServer
(Tomcat tomcat, boolean autoStart, Shutdown shutdown) Create a newTomcatWebServer
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys the web server such that it cannot be started again.int
getPort()
Return the port this server is listening on.Returns access to the underlying Tomcat server.void
shutDownGracefully
(GracefulShutdownCallback callback) Initiates a graceful shutdown of the Tomcat web server.void
start()
Starts the web server.void
stop()
Stops the web server.
-
Constructor Details
-
TomcatWebServer
Create a newTomcatWebServer
instance.- Parameters:
tomcat
- the underlying Tomcat server
-
TomcatWebServer
Create a newTomcatWebServer
instance.- Parameters:
tomcat
- the underlying Tomcat serverautoStart
- if the server should be started
-
TomcatWebServer
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
-
destroy
Description copied from interface:WebServer
Destroys the web server such that it cannot be started again.- Specified by:
destroy
in interfaceWebServer
- Throws:
WebServerException
-
getPort
public int getPort()Description copied from interface:WebServer
Return the port this server is listening on. -
getTomcat
Returns access to the underlying Tomcat server.- Returns:
- the Tomcat server
-
shutDownGracefully
Initiates a graceful shutdown of the Tomcat 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 invokingstop()
.Once shutdown has been initiated Tomcat will reject any new connections. Requests on existing idle connections will also be rejected.
- Specified by:
shutDownGracefully
in interfaceWebServer
- Parameters:
callback
- the callback to invoke when the graceful shutdown completes
-