Chapter 7: Understanding Spring Boot and Spring
This introduction shifts the focus to Spring web apps and explains why Spring Boot makes Spring applications quicker to create.
After this chapter you will be able to
- Spring Boot setup advantage. Explain that Spring Boot is a project in the Spring ecosystem that helps developers create Spring applications faster by providing ready-to-use configuration and tools for running them with less setup.
- Web app access and convenience. Explain that a web app is accessed through a web browser, unlike a desktop app installed on a computer, and describe why browser access is convenient.
- Client and server roles. Explain what the frontend and backend do in a web app and how requests and responses connect them.
- Two web app approaches. Distinguish an app whose backend sends a prepared view from one whose backend sends raw data to a separate frontend app.
- Servlet container translation role. Explain why a Java web app uses a servlet container and what it does with HTTP communication.
- Servlet request entry point. Trace how the servlet container interacts with a servlet to bring a request into the app and send a response back, and distinguish that role from writing servlets yourself in a Spring app.
- Spring Boot configuration relief. Explain why Spring Boot makes creating Spring apps more efficient: it removes much of the configuration code developers previously wrote, letting them focus on business code.
- Dependency-based default configuration. Explain that Spring Boot defines default configurations based on the project's dependencies, leaving developers to change defaults only when they do not fit.
- Spring Initializr project creation. Describe how to create a Spring Boot project through start.spring.io: choose project properties and the Spring Web dependency, generate the archive, then unpack and open it in an IDE.
- Generated project components. Describe the main class, Maven dependency and plugin, and properties file that Spring Initializr adds, including where the Maven entries and properties file appear.
- Spring Boot parent versions. Explain why the generated Maven project has a Spring Boot parent POM and why dependency versions can usually be omitted.
- Capability-oriented dependency starters. Explain that a dependency starter is added to pom.xml for a capability, such as web functionality, rather than by listing every required library. Describe how Spring Boot supplies the needed dependencies in compatible versions, avoiding manual dependency and version management.
- Dependency-based default configuration. Explain how Spring Boot uses an application's dependencies to supply default configurations, using the web dependency and Tomcat as the example. Describe why this convention-over-configuration approach reduces configuration work.
- Static page and controller. Describe how to add the section’s static web page: put the HTML document in resources/static, define a controller action for /home, and have the action return the document’s name.
- Spring MVC request flow. Trace the example request from the browser through Tomcat, the dispatcher servlet, handler mapping, the controller action, and the View Resolver to the HTTP response; explain when a 404 occurs.
What it builds on
- Using the @Bean annotation to create beans (chapter 2) · The idea of objects managed as beans in the Spring context.
- Using stereotype annotations to create beans (chapter 2) · Introduces stereotype annotations and Spring-managed beans.
Section by section
Introduction
This introduction shifts the focus to Spring web apps and explains why Spring Boot makes Spring applications quicker to create.
- Spring Boot setup advantage: Explain that Spring Boot is a project in the Spring ecosystem that helps developers create Spring applications faster by providing ready-to-use configuration and tools for running them with less setup.
Why it matters: This is the reason the chapter uses Spring Boot when it turns to web apps.
Key terms: Spring Boot, Spring ecosystem, ready-to-use configuration
7.1 What is a web app?
Defines a web app by how people access it and explains why browser access is convenient compared with installed desktop apps.
- Web app access and convenience: Explain that a web app is accessed through a web browser, unlike a desktop app installed on a computer, and describe why browser access is convenient.
Why it matters: This gives you a starting point for understanding the web apps built later in the chapter.
Key terms: web app, web browser, desktop app
7.1.1 A general overview of a web app
This section explains the client and server sides of a web app, how they exchange requests and responses, and how one backend serves multiple clients.
- Client and server roles: Explain what the frontend and backend do in a web app and how requests and responses connect them.
Why it matters: These roles provide the basic picture for understanding web apps built with Spring. - Multiple clients per backend: Describe how a web app's backend can serve multiple clients at the same time, including users on different devices.
Why it matters: A one-client diagram should not suggest that a web app can serve only one user.
Key terms: client side, server side, frontend, backend, requests, responses, multiple clients concurrently
7.1.2 Different fashions of implementing a web app with Spring
This section contrasts backend-prepared views with frontend-backend separation and explains why the latter can help larger web apps.
- Two web app approaches: Distinguish an app whose backend sends a prepared view from one whose backend sends raw data to a separate frontend app.
Why it matters: The distinction clarifies which part of a web app decides what the user sees. - Reasons for frontend separation: Explain why frontend-backend separation can be useful for larger apps and how the section contrasts its typical use with the nonseparated approach.
Why it matters: These tradeoffs help explain why both approaches appear in production apps.
Key terms: frontend-backend separation, fully prepared view, raw data, frontend app, independently managed, deployment
7.1.3 Using a servlet container in web app development
The section explains how HTTP requests reach a Spring web app through a servlet container and a servlet, without requiring developers to implement HTTP handling or servlets themselves.
- HTTP request response exchange: Describe the basic HTTP exchange between a web client and server: the client sends a request, waits, and the server responds.
Why it matters: This exchange is what the servlet container helps the Java app handle. - Servlet container translation role: Explain why a Java web app uses a servlet container and what it does with HTTP communication.
Why it matters: It separates the app's logic from the low-level work of communicating over HTTP. - Servlet request entry point: Trace how the servlet container interacts with a servlet to bring a request into the app and send a response back, and distinguish that role from writing servlets yourself in a Spring app.
Why it matters: It identifies where the container hands a request to the app without implying that you must implement a servlet. - Historical servlet path registration: Describe how developers previously connected URL paths to servlets and why the component managing those instances is called a servlet container.
Why it matters: The older path-by-path setup explains the container's name and clarifies what Spring developers generally no longer do themselves.
Key terms: HTTP, request-response, servlet container, Tomcat, HTTP messages, communication layer, servlet, entry point, HTTP request, HTTP response
7.2 The magic of Spring Boot
This section explains how Spring Boot reduces the configuration work involved in creating Spring apps and introduces three ways it does so.
- Spring Boot configuration relief: Explain why Spring Boot makes creating Spring apps more efficient: it removes much of the configuration code developers previously wrote, letting them focus on business code.
Why it matters: This explains the practical problem Spring Boot is meant to solve. - Project skeletons and dependency starters: Describe how a project initialization service supplies an empty, configured skeleton app and how dependency starters group dependencies for a purpose, including compatible versions.
Why it matters: These features reduce the decisions and setup needed before writing application code. - Dependency-based default configuration: Explain that Spring Boot defines default configurations based on the project's dependencies, leaving developers to change defaults only when they do not fit.
Why it matters: Dependency-based defaults are a central reason Spring Boot requires less manual configuration.
Key terms: Spring Boot, servlet container, business code, configurations, project initialization service, skeleton app, dependency starters, dependencies, autoconfiguration based on dependencies, default configurations
7.2.1 Using a project initialization service to create a Spring Boot project
This section shows how to generate a Spring Boot web project with Spring Initializr and identifies the main files and Maven configuration it creates.
- Spring Initializr project creation: Describe how to create a Spring Boot project through start.spring.io: choose project properties and the Spring Web dependency, generate the archive, then unpack and open it in an IDE.
Why it matters: This gives you a quick, repeatable starting point without setting up every project by hand. - Generated project components: Describe the main class, Maven dependency and plugin, and properties file that Spring Initializr adds, including where the Maven entries and properties file appear.
Why it matters: Recognizing what the initializer created helps you navigate the project before changing it. - Spring Boot parent versions: Explain why the generated Maven project has a Spring Boot parent POM and why dependency versions can usually be omitted.
Why it matters: It explains a noticeable difference from earlier Maven examples and helps prevent mismatched dependency versions.
Key terms: Spring Initializr, start.spring.io, Generate, Spring Web, Main class, @SpringBootApplication, pom.xml, Spring Boot Maven plugin, spring-boot-starter-webmvc, application.properties
7.2.2 Using dependency starters to simplify the dependency management
This section explains how Spring Boot dependency starters simplify adding capabilities by supplying compatible groups of dependencies.
- Capability-oriented dependency starters: Explain that a dependency starter is added to pom.xml for a capability, such as web functionality, rather than by listing every required library. Describe how Spring Boot supplies the needed dependencies in compatible versions, avoiding manual dependency and version management.
Why it matters: Choosing a starter lets you request what the app needs to do without assembling and checking its libraries one by one. - Web starter dependency example: Describe how adding spring-boot-starter-webmvc to pom.xml results in libraries for Spring context, AOP, and Tomcat appearing in External Libraries even though they were not individually declared.
Why it matters: The example shows the practical difference between the dependency you declare and the libraries available to the app.
Key terms: dependency starter, capabilities, pom.xml, compatible version, spring-boot-starter-webmvc, External Libraries, JAR archives, Spring context, AOP, Tomcat
7.2.3 Using autoconfiguration by convention based on dependencies
This section explains how Spring Boot uses dependencies to choose conventional default configurations, reducing the configuration developers must write.
- Dependency-based default configuration: Explain how Spring Boot uses an application's dependencies to supply default configurations, using the web dependency and Tomcat as the example. Describe why this convention-over-configuration approach reduces configuration work.
Why it matters: It explains why a newly created Spring Boot web app can start with little or no handwritten configuration.
Key terms: autoconfiguration, convention-over-configuration, web dependency, Tomcat, servlet container
7.3 Implementing a web app with Spring MVC
This section builds a simple static Spring MVC page and explains how a browser request reaches its controller and returns the page.
- Static page and controller: Describe how to add the section’s static web page: put the HTML document in resources/static, define a controller action for /home, and have the action return the document’s name.
Why it matters: It connects the page a browser displays to the request path and action that serve it. - Spring MVC request flow: Trace the example request from the browser through Tomcat, the dispatcher servlet, handler mapping, the controller action, and the View Resolver to the HTTP response; explain when a 404 occurs.
Why it matters: This flow explains both why the mapped page appears and why an unmapped request fails. - Framework setup advantage: Explain why the section says Spring and Spring Boot simplify this web app: the framework arranges much of the request-handling setup while the developer writes and maps controller actions.
Why it matters: It explains why the small amount of application code can participate in the larger request flow.
Key terms: resources/static, @Controller, controller action, @RequestMapping, Tomcat, dispatcher servlet, front controller, handler mapping, view, Spring Boot
7.4 Questions
This section lists questions for readers to check their understanding of chapter 7; it does not explain the answers.
7.5 Summary
Summarizes the web request-response flow and how Spring Boot reduces the setup needed to implement it with Spring MVC.
Where this is used later
- Summary (chapter 8) · the general overview of web apps and requests
- Using REST services to exchange data between apps (chapter 10) · Provides context for apps that exchange data rather than prepared views.
- What a data source is (chapter 12) · Spring Boot can configure components by convention.
- Using JdbcTemplate to work with persisted data (chapter 12) · Spring Boot can configure beans by convention based on dependencies.
- Implementing web apps with a dynamic view (chapter 8) · Extends a web page beyond the static example.
- (chapter intro) (chapter 8) · The prior introduction to implementing a web app with Spring MVC.
- Using the GET and POST HTTP methods (chapter 8) · Basic Spring MVC requests and controller actions.
Concepts explained in this chapter
- @requestmappingRequest mapping is the association between an HTTP request pattern and the controller handler that processes it.
- controllerA controller in Spring MVC is an application component that receives and handles web requests and produces responses.
- @ControllerThe @Controller annotation marks a class as a Spring MVC controller component eligible for management by Spring.
- web API action methodA controller action is a controller method associated with an HTTP request and responsible for producing the request's response.
- servlet containerA servlet container is server software that receives HTTP requests, sends HTTP responses, and integrates those exchanges with Java web applications.
- Spring InitializrSpring Initializr is a service that generates configured starter projects for Spring applications.
- DispatcherServletA dispatcher servlet is the Spring MVC servlet that receives web requests and coordinates their dispatch to controller actions and response rendering.
- front controllerA front controller is an architectural pattern in which a single entry point centrally processes requests and dispatches them to appropriate handlers.
- handler mappingA handler mapping is a Spring MVC component that selects a controller action for an incoming request based on request conditions such as path and HTTP method.
- static web pageA static web page is delivered as stored content rather than generated dynamically for each request.
- viewA view is the presentation resource whose content is rendered and returned as a web response.
- view resolverA view resolver is a Spring MVC component that locates a view from the name returned by a controller action.
- Spring BootSpring Boot is a Spring ecosystem project that provides convention-based default configuration for Spring applications.
- Spring Boot starterA dependency starter is a curated dependency descriptor that brings together libraries for a particular Spring Boot capability.
- web applicationA web application is software accessed through web technologies, typically using a browser as its client interface.
- backendThe execution environment where backend software runs and processes client requests.
- frontendThe client side is the part of an application that runs on a user's device and communicates with backend software.
- servletA servlet is a Java object whose methods interact with a servlet container to process HTTP requests and produce responses.
- convention over configurationConvention over configuration is a software design approach in which standard conventions supply defaults and explicit configuration is needed only for deviations.
- Spring MVCSpring MVC is the Spring web framework for developing applications that handle HTTP requests.
- SpringSpring Framework is an open-source Java framework for building enterprise and web applications.
- HTTP requestAn HTTP request is a message sent by an HTTP client to request an operation or resource from a server.
- HTTP responseAn HTTP response is a message returned by an HTTP server containing a status and optional headers and content.
- Apache TomcatTomcat is an open-source Java servlet container and web server that executes Java web components.
- application.propertiesapplication.properties is a Spring Boot configuration file that defines application settings as key-value pairs.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
