Spring Boot Auto Configuration and Dispatcher Servlet
In this section, we will see the background functionality of the application:
What is dispatcher servlet?
Who is configuring dispatcher servlet?
What does dispatcher servlet do?
How does the HelloWorldBean object gets converted to JSON?
Who is configuring the error mapping?
Spring Boot Auto Configuration
Or add the following statement in the application.properties file.
We exclude classes form the auto-configuration for faster startup and better performance of the application.
Run RestfulWebServiceApplication.java file. It shows the Positive matches, Negative matches, Exclusions, and Unconditional classes under the CONDITIONS EVALUATION REPORT.
There is a lot of information inside the report, so it is not possible to show all the detail. If we scroll down the report and have a closure look at auto configuration log, we found DispatcherServletAutoConfiguration matched.
It is because, the dependency spring-boot-starter-web depends on spring-webmvc dependency. Therefore we get the DispatcherServlet class in our classpath.
In Spring MVC all incoming requests go through a single servlet is called Dispatcher Servlet (front controller). The front controller is a design pattern in web application development. A single servlet receives all the request and transfers them to all other components of the application.
The job of DispatcherServlet is to take an incoming URI and find the right combination of handlers (Controller classes) and views (usually JSPs). When the DispatcherServlet determines the view, it renders it as the response. Finally, the DispatcherServlet returns the Response Object to back to the client. In short, the Dispatcher Servlet plays the key role.
The other thing to notice is that ErrorMvcAutoConfiguration:
It configures the basicErrorController, errorAttributes, ErrorMvcAutoConfiguration, and DefaultErrorViewResolverConfiguration. It creates the default error page which is known as Whitelabel Error Page.
The other thing which is auto-configured HttpMessageConvertersAutoConfiguration. These message converter automatically converts the message.
It initializes the Jackson bean and the message converter. The Jackson2ObjectMapper does the conversion from bean to JSON and JSON to bean.
Click here to download Quick Review of Spring Boot Auto Configuration and Dispatcher Servlet project