Spring Boot Intro
Spring Boot is the most widely used way to build server-side Java applications. It sits on top of the Spring Framework and removes most of the setup work: you add a dependency, write a class, run main, and you have a web server answering HTTP requests — no XML files, no external application server, no hand-written wiring.
This course uses Spring Boot 3.5 (built on Spring Framework 6.2) with Java 21. Everything you write uses the modern jakarta.* package names that replaced the old javax.* ones in Boot 3.
Spring Framework vs. Spring Boot
| Spring Framework | Spring Boot | |
|---|---|---|
| What it is | the core library: dependency injection, web MVC, transactions, data access | an opinionated layer on top of the framework |
| Configuration | you declare every piece yourself | sensible defaults are configured automatically |
| Server | deploy a WAR into Tomcat/Jetty | embedded Tomcat inside a runnable JAR |
| Dependencies | pick compatible versions by hand | "starters" bring a tested set of versions |
| Production tooling | add it yourself | health checks, metrics, externalised config built in |
Think of Spring Framework as a box of high-quality parts and Spring Boot as the assembled machine with the parts already connected.
A complete Spring Boot application
This is a whole working web application — one file:
package com.example.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class HelloApplication {
@GetMapping("/hello")
String hello() {
return "Hello from Spring Boot!";
}
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}SpringApplication.run starts the application context (Spring's container of objects), starts an embedded Tomcat server on port 8080, and registers the /hello endpoint. Calling it from a terminal:
curl -s localhost:8080/helloHello from Spring Boot!
Note: Spring code cannot run inside this website, so framework examples are shown as code plus a simulated terminal session with realistic output. Wherever possible, the idea behind a feature is also shown as a small plain-Java program that you can run.
The core idea: inversion of control
Most of Spring is built on one idea: your classes do not create their collaborators — the container does, and hands them in. This is called inversion of control (IoC), and handing objects in is called dependency injection (DI).
Here is that idea without any framework. The Container plays the role of Spring: it creates objects once and connects them.
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
interface Greeter {
String greet(String name);
}
class FriendlyGreeter implements Greeter {
public String greet(String name) { return "Hi, " + name + "!"; }
}
class WelcomeService {
private final Greeter greeter;
WelcomeService(Greeter greeter) { this.greeter = greeter; } // injected, not created
String welcome(String user) { return greeter.greet(user); }
}
class Container {
private final Map<Class<?>, Object> beans = new HashMap<>();
<T> void register(Class<T> type, Supplier<T> factory) { beans.put(type, factory.get()); }
<T> T get(Class<T> type) { return type.cast(beans.get(type)); }
}
class Main {
public static void main(String[] args) {
Container ctx = new Container();
ctx.register(Greeter.class, FriendlyGreeter::new);
ctx.register(WelcomeService.class, () -> new WelcomeService(ctx.get(Greeter.class)));
WelcomeService service = ctx.get(WelcomeService.class);
System.out.println(service.welcome("Ada"));
System.out.println("Same instance: " + (service == ctx.get(WelcomeService.class)));
}
}Hi, Ada!
Same instance: true
Spring does the same, but it discovers the classes by scanning your packages and reading annotations, so you never write the register calls yourself.
What you can build
- REST APIs and microservices (the focus of this course)
- server-rendered web apps (Thymeleaf)
- batch jobs, message consumers (Kafka, RabbitMQ), scheduled tasks
- reactive services with WebFlux
What you will learn
- Basics — project setup, beans, dependency injection, configuration and profiles.
- REST APIs — controllers, JSON, validation, error handling, DTOs.
- Data access — Spring Data JPA, repositories, transactions, pagination, migrations.
- Production — security, testing, Actuator, Docker and environment configuration.
- Practice — exercises and a complete task-tracker API.
Tip: You should be comfortable with Java classes, interfaces, annotations, collections and records before starting. The Java course on this site covers all of them.
Test yourself
What does Spring Boot add on top of the Spring Framework?
- A new programming language
- Auto-configuration, starters and an embedded server
- A replacement for the JVM
- A JavaScript front-end framework
In inversion of control, who creates a class's collaborators?
- The class itself with
new - The container, which injects them
- The operating system
- The HTTP client
Which package prefix do Spring Boot 3 applications use for Servlet, JPA and validation APIs?
javax.*jakarta.*spring.*java.ee.*