Package com.bobocode.bring.web.servlet
Class WebStarter
java.lang.Object
com.bobocode.bring.web.servlet.WebStarter
The
WebStarter
class is responsible for initializing and running a web application
using Apache Tomcat as the embedded servlet container.
This class sets up the necessary components such as the servlet container, dispatcher servlet, exception handler, and REST controller context. It also configures the servlet mappings and starts the web server.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Attribute key for storing the BringApplicationContext in the servlet context.static final String
Default name for the dispatcher servlet.private final DispatcherServlet
The DispatcherServlet responsible for handling HTTP requests.private final JsonExceptionHandler
The JsonExceptionHandler for handling JSON-related exceptions.static final String
Attribute key for storing the REST controller parameters map in the servlet context.private final RestControllerContext
The RestControllerContext for managing REST controllers and their parameters.private final ServletWebServerFactory
The ServletWebServerFactory used to create the embedded servlet container.static final String
Default URL pattern for the dispatcher servlet.private TomcatWebServer
The TomcatWebServer instance representing the embedded Tomcat server. -
Constructor Summary
ConstructorsConstructorDescriptionWebStarter
(TomcatServletWebServerFactory tomcatServletWebServerFactory, DispatcherServlet dispatcherServlet, JsonExceptionHandler jsonExceptionHandler, RestControllerContext restControllerContext) Constructs a new WebStarter with the specified components. -
Method Summary
-
Field Details
-
BRING_CONTEXT
Attribute key for storing the BringApplicationContext in the servlet context.- See Also:
-
REST_CONTROLLER_PARAMS
Attribute key for storing the REST controller parameters map in the servlet context.- See Also:
-
DISPATCHER_SERVLET_NAME
Default name for the dispatcher servlet.- See Also:
-
URL_PATTERN
Default URL pattern for the dispatcher servlet.- See Also:
-
servletWebServerFactory
The ServletWebServerFactory used to create the embedded servlet container. -
dispatcherServlet
The DispatcherServlet responsible for handling HTTP requests. -
jsonExceptionHandler
The JsonExceptionHandler for handling JSON-related exceptions. -
restControllerContext
The RestControllerContext for managing REST controllers and their parameters. -
webServer
The TomcatWebServer instance representing the embedded Tomcat server.
-
-
Constructor Details
-
WebStarter
public WebStarter(TomcatServletWebServerFactory tomcatServletWebServerFactory, DispatcherServlet dispatcherServlet, JsonExceptionHandler jsonExceptionHandler, RestControllerContext restControllerContext) Constructs a new WebStarter with the specified components.- Parameters:
tomcatServletWebServerFactory
- The factory for creating the embedded Tomcat server.dispatcherServlet
- The DispatcherServlet for handling HTTP requests.jsonExceptionHandler
- The JsonExceptionHandler for handling JSON-related exceptions.restControllerContext
- The RestControllerContext for managing REST controllers and parameters.
-
-
Method Details
-
run
public void run(com.bobocode.bring.core.context.impl.BringApplicationContext bringApplicationContext) Runs the web application.- Parameters:
bringApplicationContext
- The BringApplicationContext for the application.
-
stop
public void stop()Stops the embedded Tomcat server.
-