DEV Community

Cover image for Getting Started with Spring Boot: A Beginner’s Guide
Tejas Agravat
Tejas Agravat

Posted on

Getting Started with Spring Boot: A Beginner’s Guide

Introduction

Spring Boot is a powerful Java framework that makes it easier to build modern backend applications. In this guide, you’ll learn the basics of Spring Boot, how to create a project, understand its structure, manage dependencies, and build a simple REST API.


Canonical Link

https://tejas-agravat.hashnode.dev/getting-started-with-spring-boot-a-beginners-guide


🧠 Prerequisites

Before we begin, you should have a basic understanding of:

  • Core Java concepts
  • Object-Oriented Programming (OOP)
  • Classes, methods, and interfaces
  • Basic database concepts (tables, primary keys, foreign keys)
  • Writing simple SQL queries

These fundamentals will help you follow along more easily.


🎯 What You’ll Learn

In this article, you will cover:

  • What Spring Boot is
  • Why Spring Boot was introduced
  • Creating a Spring Boot project
  • Understanding project structure
  • Managing dependencies with Maven
  • Building and running a Spring Boot app
  • Creating a simple REST API

Source Code

You can go through the Git link to check out the exact code. I write each lesson in a way that makes it easy for you to follow on your own. I have organized the source code in a GitHub repository, which you can find at github.com


📦 Introduction to Spring Boot

Spring Boot is a Java framework built on top of the Spring Framework. It simplifies development by reducing manual configurations and setup.

Instead of writing extensive XML or Java configuration and setting up external servers, Spring Boot provides:

  • Auto-configuration
  • Embedded servers
  • Opinionated defaults
  • Easy REST API support

This makes it ideal for building standalone, production-ready applications.


🧩 Why Spring Boot Was Introduced

Before Spring Boot:

  • Projects required lots of configuration
  • Developers wrote repetitive boilerplate code
  • Dependency management was manual
  • You needed an external application server

Spring Boot solves these pain points by standardizing and automating much of the setup.


⭐ Key Features of Spring Boot

Auto-Configuration — Automatically configures the app based on dependencies.

Embedded Servers — Includes Tomcat/Jetty, so no external server is needed.

Easy REST APIs — Build web APIs with minimal code.

Database Integration — Works well with JDBC, JPA, and popular databases.

Spring Security Support — Built-in authentication and authorization support.


🚀 Create a Spring Boot Project

The easiest way is using Spring Initializr:

👉 https://start.spring.io

Steps

  1. Open Spring Initializr
  2. Configure project:
    • Project: Maven
    • Language: Java
    • Spring Boot Version: Default
    • Group: com.codewithtejas
    • Artifact: store
    • Java Version: 17
  3. Add Spring Web dependency
  4. Click Generate
  5. Extract the downloaded .zip file into your workspace

📁 Understanding Project Structure

store
├── .mvn
├── src
│ ├── main
│ │ ├── java
│ │ └── resources
├── pom.xml
Enter fullscreen mode Exit fullscreen mode

Important Parts

  • pom.xml — Manages dependencies and build.
  • mvnw / mvnw.cmd — Maven wrapper scripts for consistent builds.
  • src/main/java — Application source code.
  • src/main/resources — Config files like application.properties.
  • src/test/java — Test cases (JUnit).
  • target/ — Auto-generated build output.

🛠 Managing Dependencies with Maven

Dependencies are defined in pom.xml:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Enter fullscreen mode Exit fullscreen mode
  • groupId → Organization or project group
  • artifactId → Library name
  • version → Library version

  • 👉 In Spring Boot, versions are often managed automatically.

spring-boot-starter-web
Enter fullscreen mode Exit fullscreen mode

This single dependency includes:

  • Spring MVC
  • Embedded Tomcat
  • Jackson (JSON)
  • Validation

Updating Dependencies

After modifying pom.xml:

IDE automatically reloads

Or run:

mvn clean install
Enter fullscreen mode Exit fullscreen mode

Building and running a Spring Boot application

Creating a Simple REST Controller**

Step 1: Create a Controller Class**

Create a new package:

com.codewithtejas.store.controller
Enter fullscreen mode Exit fullscreen mode

Create a class:

@RestController
@RequestMapping("/api")
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello from Spring Boot!";
    }
}
Enter fullscreen mode Exit fullscreen mode

Explanation of Annotations

  • @RestController → Marks the class as a REST controller
  • @RequestMapping("/api") → Base URL path
  • @GetMapping("/hello") → Handles HTTP GET requests

Run Using Maven Wrapper (Terminal / CMD)

** Go to the project root (where pom.xml exists).**

Run Using Maven (If Installed)

mvn spring-boot:run
Enter fullscreen mode Exit fullscreen mode

Open:

http://localhost:8080/hello
Enter fullscreen mode Exit fullscreen mode

🚀 What’s Next?

Now that you understand the basics of Spring Boot, the next important step is learning Dependency Injection (DI) and the Inversion of Control (IoC) Container.

These concepts are the foundation of the Spring Framework and are used everywhere in Spring Boot applications.

Let’s Connect!

Linkedin Github

If you have any recommended resources, better approaches to my challenges, or insights, I’d love to hear them! Drop your thoughts in the comments.

Have a wonderful day!

Top comments (0)