Spring Boot
In short
Spring Boot is a Java framework for quickly building production-ready services on top of Spring, with auto-configuration and an embedded web server.
What is Spring Boot?
The Spring Framework has been a foundation of enterprise Java since the early 2000s, known for dependency injection and its many modules for web, data and security. It was also known for heavy configuration. Spring Boot, first released in 2014, removed most of that: you add a starter dependency such as spring-boot-starter-web, and Boot configures the pieces automatically based on what it finds.
A Spring Boot application runs as a single executable JAR with an embedded server such as Tomcat, so you start it with java -jar app.jar instead of deploying into a separate application server. Controllers are plain classes with annotations such as @RestController and @GetMapping, and Spring wires dependencies into them through their constructors.
Around the core is a large ecosystem: Spring Data for databases with JPA and Hibernate, Spring Security for authentication, Spring Cloud for microservice patterns, and Actuator for health checks and metrics. Spring Initializr generates a ready project, and Spring Boot 3 requires Java 17 or later and supports compiling to native images with GraalVM.
A common misconception is that Spring Boot is a different framework from Spring. It is a layer on top of Spring that chooses defaults and wires things up; underneath it is still the Spring Framework, and any default can be overridden when a project needs something different.
Key takeaways
- Spring Boot builds production-ready Java apps on the Spring Framework.
- Starters and auto-configuration replace most manual setup.
- Apps run as a single JAR with an embedded server such as Tomcat.
- Spring Data, Security and Actuator cover databases, auth and monitoring.
- It is a layer of defaults on Spring, not a separate framework.
Example
@SpringBootApplication
public class BookApplication {
public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args); // starts the embedded server
}
}
@RestController
@RequestMapping("/books")
class BookController {
private final BookRepository books;
BookController(BookRepository books) { // injected by Spring
this.books = books;
}
@GetMapping("/{id}")
ResponseEntity<Book> get(@PathVariable Long id) {
return books.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
}Readers ask
What is the difference between Spring and Spring Boot?
Spring is the underlying framework with dependency injection and many modules. Spring Boot sits on top of it and adds auto-configuration, starter dependencies and an embedded server, so a Spring application needs far less setup.
Is Spring Boot used for microservices?
Very often. Small, self-contained executable JARs, health checks through Actuator and the Spring Cloud projects make it a common choice for Java microservices.
Can I use Kotlin with Spring Boot?
Yes. Spring Boot officially supports Kotlin, and Spring Initializr can generate Kotlin projects with Gradle or Maven.
See also
- JavaProgramming Languages, p. 15Java is a statically typed, object-oriented programming language that compiles to bytecode for the Java Virtual Machine, so programs run on many platforms.
- Dependency InjectionSoftware Architecture, p. 12Dependency injection is a design technique in which an object receives the other objects it needs from the outside instead of creating them itself.
- MicroservicesSoftware Architecture, p. 27Microservices are an architectural style where an application is split into small, independently deployable services that communicate over a network.
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- ORMDatabases, p. 33An ORM is a library that maps database tables to objects in your programming language, letting you read and write data with code instead of raw SQL.
- KotlinProgramming Languages, p. 18Kotlin is a concise, statically typed language that runs on the JVM, works seamlessly with Java, and is widely used for Android and server-side development.
Spotted a mistake or something missing on this page?Suggest an edit