On this page
Spring Boot
Prev: Spring Framework | Up: third_party/java | Next: interop
Rel: Spring Framework, Jackson, Apache Maven, Gradle, JUnit 5, record
Ref: Spring Boot Reference Documentation
Tags: #public #prog #java #third-party #framework #web #tier/core
Overview
Spring Boot builds on top of Spring Framework to eliminate boilerplate XML/Java setup. It provides opinionated starter dependencies, auto-configuration driven by what is on the classpath, an embedded servlet/reactive server (Tomcat, Jetty, or Undertow) packaged into a runnable fat JAR, and production observability via Actuator.
Core Building Blocks
| Feature | How It Works |
|---|---|
| Starters | Curated POMs like spring-boot-starter-web, spring-boot-starter-data-jpa, spring-boot-starter-test that align transitive versions |
| Auto-Configuration | @SpringBootApplication scans components and conditionally registers beans (@ConditionalOnClass, @ConditionalOnMissingBean) |
| Externalized Config | application.yml / application.properties, environment variables, and profiles (spring.profiles.active=prod) bound to typed @ConfigurationProperties records |
| Embedded Server | Runs directly via java -jar app.jar—no external WAR deployment container needed |
| Actuator | Adds /actuator/health, /actuator/metrics, and /actuator/info endpoints for container liveness/readiness probes |
Minimal REST Service + Typed Config (Java 21)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@ConfigurationPropertiesScan
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
// Bound automatically from app.greeting in application.yml
@ConfigurationProperties(prefix = "app")
record AppProperties(String greeting) {}
@RestController
class HelloController {
private final AppProperties props;
HelloController(AppProperties props) {
this.props = props;
}
@GetMapping("/hello/{name}")
MessageResponse hello(@PathVariable String name) {
return new MessageResponse(props.greeting() + ", " + name);
}
record MessageResponse(String message) {}
}
Virtual Threads on Spring Boot 3.2+ (Java 21)
Enable virtual threads for Tomcat/Jetty request handling with a single property in application.yml:
spring:
threads:
virtual:
enabled: true
Testing Slices vs. Full Context
- Unit tests: Instantiate classes directly with JUnit 5 (no Spring context, millisecond startup).
- Web slice tests (
@WebMvcTest): Load only the controller + Jackson +MockMvcwithout starting databases or unrelated beans. - Integration tests (
@SpringBootTest): Boot the full application context for end-to-end verification.
Linked from
Related notes
- tuts/third_party/java/spring_framework Linked here; links to this page; shared tags: #framework, #java, #prog, #tier, #web
- tuts/third_party/java Linked here; links to this page; shared tags: #java, #prog
- tuts/java/builtins/record Linked here; shared tags: #java, #prog, #tier
- tuts/third_party/java/gradle Linked here; shared tags: #java, #prog, #tier
- tuts/third_party/java/jackson Linked here; shared tags: #java, #prog, #tier
- tuts/third_party/java/junit Linked here; shared tags: #java, #prog, #tier
- tuts/third_party/java/maven Linked here; shared tags: #java, #prog, #tier
- tuts/java links to this page; shared tags: #java, #prog
- tuts/interop Linked here; shared tags: #prog
- tuts/interop/java_and_c_ffm_and_jni shared tags: #java, #prog, #tier