About Us Contact Us Write for Us Advertise
Home > Java > Build Your First Spring Boot App (Step-by-Step Beginner Guide)
Java

Build Your First Spring Boot App (Step-by-Step Beginner Guide)

Build and run your first Spring Boot web app step by step: Spring Initializr setup, the main class, a REST endpoint, running it, and fixing common first-timer errors.

Shiv Pandey
Shiv Pandey
Oct 03, 2026 | 39 views
Build Your First Spring Boot App (Step-by-Step Beginner Guide)

Enough theory — let's build something that runs! In this lesson you'll create your very first Spring Boot application from scratch and see it respond in your browser. We'll go step by step, explaining each piece, so by the end you'll have a working web app and understand what every part does. This is the satisfying "it's alive!" moment.

Step 1: Generate the project with Spring Initializr

The easiest way to start any Spring Boot project is Spring Initializr — a free website (start.spring.io) that generates a ready-to-run project skeleton for you. You pick a few options and it hands you a zip file. Choose:

  • Project: Maven (the build tool — it manages your libraries)
  • Language: Java
  • Spring Boot version: the latest stable (non-snapshot) one
  • Dependencies: add Spring Web (this gives you everything to build web endpoints)

Click Generate, unzip the download, and open the folder in your IDE (IntelliJ IDEA or VS Code). That's your project — no manual setup required.

Step 2: Understand what you were given

Inside, you'll find a main class that Spring Initializr created — the entry point of your whole app:

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

Two things are happening here:

  • @SpringBootApplication — the master annotation that turns on auto-configuration and tells Spring to scan this package for your components (we met it in Lesson 1).
  • SpringApplication.run(...) — this line actually starts everything: it launches the IoC container and the embedded web server.

Step 3: Write your first endpoint

Right now the app runs but doesn't respond to anything. Let's add a web endpoint — a URL your app answers. Create a new class called HelloController:

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot!";
    }
}

Let's decode those two annotations, because you'll use them constantly:

  • @RestController — tells Spring "this class handles web requests, and whatever the methods return is the response body."
  • @GetMapping("/hello") — "when someone visits /hello with a GET request (i.e. a browser), run this method."

So visiting /hello will call hello() and send back the text it returns. Notice you didn't configure a server, a route table, or anything else — Spring wires it all up from these annotations.

Step 4: Run it!

Run the main method (your IDE has a green ▶ button), or from a terminal:

./mvnw spring-boot:run

Watch the console — you'll see Spring Boot's logo and startup logs, ending with a line like "Tomcat started on port(s): 8080". Your app is live! Now open a browser and go to:

http://localhost:8080/hello

You'll see Hello, Spring Boot! on the page. Congratulations — you just built and ran a real web application! 🎉

What just happened, end to end: the embedded Tomcat server received your browser's request for /hello, Spring matched it to your hello() method, ran it, and sent the returned text back as the response. All from a few annotations and one run() call. That's the Spring Boot magic in action.

Troubleshooting the common first-timer snags

  • "Port 8080 already in use" — something else is using that port. Add server.port=8081 to src/main/resources/application.properties and try again.
  • 404 Not Found — double-check the URL path matches your @GetMapping exactly, and that HelloController is in the same package (or a subpackage) as your main class, so component-scanning finds it.
  • Nothing happens — make sure you ran the main method, and watch the console for errors.

I still remember the little thrill of seeing my first "Hello" render in the browser — it's a small thing, but it's the moment backend development stops being abstract and becomes real. My honest advice: don't just copy this and move on. Change the message. Add a second endpoint at /bye. Break something on purpose and read the error. That hands-on tinkering, in these very first minutes, teaches you more than hours of reading. This website started as exactly this kind of tiny app — one controller, one endpoint — and grew from there. So will your skills.

Key takeaways

  • Generate a project with Spring Initializr (start.spring.io), adding the Spring Web dependency.
  • The @SpringBootApplication main class + SpringApplication.run(...) boot the whole app and server.
  • A @RestController with @GetMapping("/path") creates a web endpoint that returns a response.
  • Run it, visit http://localhost:8080/hello, and you've built a real web app — then experiment!

← Previous: Spring Lesson 2 — IoC & Dependency Injection
Next: Spring Lesson 4 — Essential Spring Boot Annotations →
↑ Back to the Spring Boot roadmap

Related Articles

Build a Spring Boot CRUD App with a Database (Step by Step)
Java

Build a Spring Boot CRUD App with a Database (Step by Step)

Build a Spring Boot REST API Project (Step by Step)
Java

Build a Spring Boot REST API Project (Step by Step)

Deploying a Spring Boot App to Production (Beginner Guide)
Java

Deploying a Spring Boot App to Production (Beginner Guide)

Dockerizing a Spring Boot App (Beginner Guide)
Java

Dockerizing a Spring Boot App (Beginner Guide)