Skip to content

Spring Boot Lab Setup and Reading Order

Interactive Diagram

새 탭 ↗

Spring Boot helps configure dependencies, apply auto-configuration, and package Spring applications. An executable jar with an embedded server offers an alternative to deploying a WAR into a separately managed server.

These chapters use small examples to teach bean injection, HTTP requests and responses, external API calls, SQL mapping, and configuration to readers who know basic Java. Create the shared project first, then add the files needed by each chapter.

ComponentBaseline
JavaJDK 17 or later, source level 17
Spring Boot3.5.16
Maven3.6.3 or later
MyBatis StarterAdd 3.0.4 in the MyBatis chapter
DatabaseUse H2 in the MyBatis chapter

Check the official system requirements for the Java compatibility range of Spring Boot 3.5. Keep example dependencies aligned with this baseline, and review support status and security updates for the version used in a real service.

Create these two files in an empty directory. Each code block title specifies its path. Work in a separate copy of the base project for each chapter so its application.properties and initialization data do not overwrite those of another chapter.

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
12 collapsed lines
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.16</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>tutorial</artifactId>
<version>1.0.0</version>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

spring-boot-starter-web provides Spring MVC and an embedded web server. This exercise includes spring-boot-starter-webflux for WebClient. With both starters present, the default web application type is Spring MVC. The test dependency provides JUnit and Spring testing tools.

src/main/java/com/example/tutorial/TutorialApplication.java
package com.example.tutorial;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TutorialApplication {
public static void main(String[] args) {
SpringApplication.run(TutorialApplication.class, args);
}
}

Keep all example classes under com.example.tutorial so they fall within the default component scan of @SpringBootApplication. The MyBatis chapter’s mappers are discovered within the same boundary.

Run these commands in sequence from the project root.

Terminal window
java -version
mvn -version
mvn test
mvn package
java -jar target/tutorial-1.0.0.jar

mvn test runs the tests you add. The base project alone has no tests. mvn package runs tests and builds an executable jar. Start the server with the final command and stop it with Ctrl+C.

The base project has no HTTP routes yet, so a 404 response at / is expected. Add a controller from the REST API chapter before requesting its routes. During development, mvn spring-boot:run can start the application directly.

  1. Beans and constructor injection: Select beans of one interface and check the returned values.
  2. REST API requests and JSON responses: Separate input locations, object serialization, status codes, and headers.
  3. External API calls with WebClient: Configure addresses and timeouts and connect asynchronous responses.
  4. MyBatis and H2: Use seed data and mappers to check inserts, queries, and deletes.
  5. Configuration and effective values: Apply profiles and external configuration to the same jar.

Save a block whose title is a path to that file. Blocks labeled as fragments, such as pom.xml (dependencies), belong inside the corresponding part of the base file. Configuration and SQL under src/main/resources are packaged as classpath resources.

Expected responses and test code give readers a comparison target. Prepare external API addresses, secret injection, and production databases according to each chapter’s scope. Design authentication, authorization, and production deployment policies around the service’s own requirements.