Your First Spring Boot Application: Zero to Running in 10 Minutes
Java & Spring Boot for Beginners · Part 8 of 14
- #Java
- #Spring Boot
- #Beginners
- #Tutorial
Part 7 walked through what Spring Boot does mechanically — starters, auto-configuration, dependency injection — without a single running application to point at. Fair warning stops here. This post generates a real project, runs it, and hits two live endpoints, and by the end you'll have something on disk instead of a mental model. Ten minutes is a genuine estimate, not a marketing one — most of it is Maven downloading the internet the first time.
Generating the project with Spring Initializr
You don't hand-write a Spring Boot project's skeleton. You go to start.spring.io, pick a handful of options, and download a zip with everything already wired together. This is Spring's own tool, and it's also built into IntelliJ's "New Project" wizard if you'd rather not leave the IDE — same generator underneath either way.
Fill it in like this:
- Project: Maven (Part 6 covered why I'd point a beginner at Maven first — Gradle works identically here if you'd rather use it)
- Language: Java
- Spring Boot version: the latest stable release, not a
SNAPSHOT - Group:
dev.josealencar(use your own reverse-domain — this becomes your base Java package) - Artifact:
task-tracker - Packaging: Jar
- Java: 21 (or 25 — whichever current LTS you landed on back in Part 2)
- Dependencies: add Spring Web and Spring Boot Actuator
Those two dependencies matter. Spring Web pulls in an embedded Tomcat and Spring MVC, which is what turns this from "a Java program" into "a web service." Actuator gives you a handful of operational endpoints for free, including the health check we're about to hit. Click Generate, unzip the download, and open the folder in your editor.
Touring the folder Initializr just gave you
Open it up and it's smaller than you'd expect for something described as "enterprise-grade." Here's what's actually in there and why:
task-tracker/
├── mvnw, mvnw.cmd # the Maven wrapper from Part 6 — always use this
├── pom.xml # your dependencies: web, actuator, and their versions
├── src/
│ ├── main/
│ │ ├── java/dev/josealencar/tasktracker/
│ │ │ └── TaskTrackerApplication.java # the entry point
│ │ └── resources/
│ │ └── application.properties # config: empty for now
│ └── test/
│ └── java/dev/josealencar/tasktracker/
│ └── TaskTrackerApplicationTests.java
pom.xml is exactly the shape Part 6 walked through — a
spring-boot-starter-parent, the two starters you picked, and the
Spring Boot Maven plugin, with no version numbers next to the starters
because the parent's bill of materials supplies them. application.properties
is where configuration goes once you have any — right now it's an empty
file, which is itself worth noticing: a Spring Boot app runs fine with zero
lines of configuration. The test folder already has one generated test
that does nothing but verify the application context starts, which is a
lower bar than it sounds and still catches a surprising number of "I broke
the whole app" mistakes.
@SpringBootApplication, unpacked
Open TaskTrackerApplication.java. It's short enough to paste in full:
package dev.josealencar.tasktracker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TaskTrackerApplication {
public static void main(String[] args) {
SpringApplication.run(TaskTrackerApplication.class, args);
}
}
That's the whole entry point. @SpringBootApplication is doing the heavy
lifting, and it's worth knowing it isn't one annotation — it's three,
bundled:
@Configuration— this class can itself declare beans@EnableAutoConfiguration— the classpath-scanning mechanism from Part 7 that registers beans based on what starters you added@ComponentScan— scan this package and everything below it for@Component,@Service,@Repository, and@RestControllerclasses and register them
That last one is why package placement matters more than it looks like it
should: anything you write outside dev.josealencar.tasktracker and its
subpackages won't be found unless you scan for it explicitly. Keep your
classes under the package the generator gave you and this never comes up.
SpringApplication.run(...) is the line that actually does something at
runtime — it bootstraps the Spring container, runs auto-configuration,
starts the embedded Tomcat, and blocks, keeping the process alive to serve
requests.
Running it
From the project root:
./mvnw spring-boot:run
The wrapper downloads Maven itself the first time (that's most of your ten minutes), then compiles and starts the app. You'll see a wall of log lines ending in something like:
Tomcat started on port 8080 (http) with context path '/'
Started TaskTrackerApplication in 1.412 seconds (process running for 1.688)
That's it. That's a running web service, entirely from an empty project you downloaded a few minutes ago. Open a second terminal — the first one is busy running the app — and hit the health endpoint Actuator gave you for free:
curl http://localhost:8080/actuator/health
# {"status":"UP"}
You didn't write a line of code for that. It's Actuator's starter reacting to what's on the classpath, exactly the auto-configuration mechanism from Part 7, giving you a real signal a load balancer or a Kubernetes liveness probe can check.
Adding your first endpoint
/actuator/health is Spring's, not yours. Let's add one that is. This is
also where I need to make a choice I'm going to stick with for the rest of
the series: the example domain everything from here forward builds on.
I'm picking a small task-tracking API — a Task with an id, a title,
and a done flag. It's deliberately boring. Over the next six parts this same
domain grows a real REST API (Part 9), a database behind it with Spring Data
JPA (Part 10), input validation and proper error handling (Part 11), tests
(Part 12), authentication (Part 13), and a packaged, deployed artifact
(Part 14). A task list is small enough to hold in your head at every one of
those steps and real enough that adding a database or a security layer to
it doesn't feel arbitrary.
Create Task.java next to TaskTrackerApplication.java:
package dev.josealencar.tasktracker;
public record Task(Long id, String title, boolean done) {}
A record, from the language fundamentals in Part 4 — no getters, equals, or
toString to hand-write for something that's just a shape holding data. Now
a controller, TaskController.java, in the same package:
package dev.josealencar.tasktracker;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class TaskController {
@GetMapping("/api/tasks")
public List<Task> listTasks() {
return List.of(
new Task(1L, "Read Part 8 of the series", true),
new Task(2L, "Wire this up to a real database", false)
);
}
}
@RestController is @Controller plus @ResponseBody — every method's
return value gets serialized straight to JSON in the HTTP response instead
of being resolved as a view name, which is the behavior you want for an
API and not for a server-rendered page. @GetMapping("/api/tasks") maps
GET /api/tasks to this method. Jackson, pulled in transitively by
spring-boot-starter-web, handles turning the List<Task> into JSON with
no configuration from you.
Stop the running app (Ctrl+C in the first terminal) and restart it, then:
curl http://localhost:8080/api/tasks
[
{"id":1,"title":"Read Part 8 of the series","done":true},
{"id":2,"title":"Wire this up to a real database","done":false}
]
Component scanning is why TaskController got picked up automatically —
you didn't register it anywhere, you just annotated it and left it in a
package @ComponentScan already covers.
What you actually have now
A generated project, a folder structure you can navigate on sight, an annotation you can explain instead of just paste, a running process answering two real HTTP requests, and a domain — tasks — that the rest of this series is going to keep extending instead of throwing away. That last part matters more than it might seem: most tutorials pick a new toy example for every post, and you never get the experience of a project actually growing. This one will.
Right now listTasks() returns a hardcoded list that resets every time you
restart the app, which is obviously not a real API yet — it doesn't take
input, can't create or update anything, and forgets everything the moment
the JVM stops. Part 9 fixes the first half of that: a proper REST API over
this same Task domain, with POST, PUT, and DELETE alongside the
GET you already have.