liveBook · Manning

Spring Boot

As explained in Spring in Action, Sixth Edition

A Spring application built with Spring Boot, typically packaged with the components needed to run as a self-contained application.

Spring Boot extends the Spring Framework to make applications quicker to set up. Its starter dependencies collect related libraries, while autoconfiguration uses the classpath, environment properties, and other clues to configure components. That leaves less Java or XML configuration to write by hand. section 1.1 section 1.5

To start a web application:

  • Generate a project with Spring Initializr, directly or through Spring Tool Suite. Choose a Spring Boot version and the dependencies the application needs. section 1.2.1
  • Put application code under src/main/java and tests under src/test/java. Use application.properties for configuration properties; place browser assets in static and view templates in templates. section 1.2.2
  • Launch the generated main class. Its @SpringBootApplication annotation identifies the bootstrapping class, and its main method calls SpringApplication.run(...). section 1.2.2
Listing 1.2 The Taco Cloud bootstrap class
package tacos;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication                                        #1
public class TacoCloudApplication {
 
  public static void main(String[] args) {
    SpringApplication.run(TacoCloudApplication.class, args);  #2
  }
 
}

The generated bootstrap class shows how little launch code is needed: an annotated class with a main method that runs the application. section 1.2.2

A web page without server setup

Add the Web and Thymeleaf starters to a web application. They bring in Spring MVC, an embedded Tomcat server, and Thymeleaf. At startup, autoconfiguration sets up the MVC beans, server, and view resolver. Run the application in Spring Tool Suite or with ./mvnw spring-boot:run, then open http://localhost:8080. Tomcat is part of the application; you did not deploy the application to a separate server. section 1.3.6 section 1.3.4 section 1.2.2

A generated @SpringBootTest can check that the application context loads. For deployment, package the application as an executable JAR, a WAR for a traditional Java application server, or a container image. Spring Boot also provides runtime insights through Actuator and additional testing support. section 1.2.2 section 18.1 section 1.4.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through project generation, bootstrap code, startup, and autoconfiguration effects; stops short of detailing autoconfiguration internals.
Examples
Uses a generated Maven web application, its bootstrap class, an application-context test, and a home page served on localhost.
What it assumes
Introduces the generated Spring project structure and bootstrap class while treating familiarity with Maven build fields as optional.
What you can do after
Build it from scratch with Spring Initializr, run it locally, and choose a JAR, WAR, or container image for deployment.
How it connects
Connects starter dependencies and autoconfiguration to Spring MVC, embedded Tomcat, Thymeleaf, and the Spring application context.

Also explained in

Compare how 4 books explain Spring Boot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.