Spring Boot Project Setup (Spring Initializr)

2 minute read

Let’s create your first Spring Boot application in under 5 minutes. We’ll use Spring Initializr — Spring’s official project generator.


Spring Initializr (start.spring.io)

Go to start.spring.io and configure:

Setting Value
Project Maven
Language Java
Spring Boot 3.3.x (latest stable)
Group com.bookstore
Artifact bookstore-api
Name bookstore-api
Packaging Jar
Java 21

Dependencies to Add

  • Spring Web — REST APIs
  • Spring Data JPA — Database access
  • H2 Database — In-memory DB for development
  • Spring Boot DevTools — Hot reload
  • Lombok — Reduce boilerplate
  • Validation — Bean validation

Click Generate → download ZIP → extract → open in your IDE.

Or via CLI

curl https://start.spring.io/starter.zip \
  -d type=maven-project \
  -d language=java \
  -d bootVersion=3.3.0 \
  -d baseDir=bookstore-api \
  -d groupId=com.bookstore \
  -d artifactId=bookstore-api \
  -d name=bookstore-api \
  -d javaVersion=21 \
  -d dependencies=web,data-jpa,h2,devtools,lombok,validation \
  -o bookstore-api.zip

unzip bookstore-api.zip
cd bookstore-api

Project Structure

bookstore-api/
├── pom.xml
├── src/
│   ├── main/
│   │   ├── java/com/bookstore/
│   │   │   └── BookstoreApiApplication.java
│   │   └── resources/
│   │       ├── application.properties
│   │       ├── static/          ← Static files (CSS, JS)
│   │       └── templates/       ← Server-side templates
│   └── test/
│       └── java/com/bookstore/
│           └── BookstoreApiApplicationTests.java
└── mvnw / mvnw.cmd             ← Maven wrapper

The Main Application Class

package com.bookstore;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BookstoreApiApplication {

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

@SpringBootApplication combines three annotations:

Annotation Purpose
@Configuration Marks this class as a configuration source
@EnableAutoConfiguration Enables auto-configuration based on classpath
@ComponentScan Scans this package and sub-packages for beans

Running the Application

From IDE

Right-click BookstoreApiApplication → Run

From Terminal

./mvnw spring-boot:run

As a JAR

./mvnw clean package
java -jar target/bookstore-api-0.0.1-SNAPSHOT.jar

Output:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.0)

Started BookstoreApiApplication in 2.3 seconds (process running for 2.7)

The app runs on http://localhost:8080 by default.


Your First Endpoint

Create a quick test endpoint:

package com.bookstore.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Welcome to the Bookstore API!";
    }
}
$ curl http://localhost:8080/hello
Welcome to the Bookstore API!

DevTools — Hot Reload

With spring-boot-devtools, the app restarts automatically when you change code:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

Save a file → Spring Boot restarts in ~1 second → changes available immediately.

DevTools is automatically disabled in production (when running from a JAR).


Key pom.xml Dependencies

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.0</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

spring-boot-starter-parent provides dependency management — no versions needed for starter dependencies.


Common Mistakes

Mistake Fix
Main class not in root package @ComponentScan only scans its package and below
Port 8080 already in use Use server.port=8081 in application.properties
Missing Maven wrapper Run mvn wrapper:wrapper to generate
Using gradle instead of ./gradlew Always use the wrapper

Key Takeaways

  1. Spring Initializr generates a ready-to-run project with your chosen dependencies.
  2. @SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan.
  3. Run with ./mvnw spring-boot:run or as a JAR.
  4. DevTools enables hot reload during development.
  5. spring-boot-starter-parent manages all dependency versions.

What’s Next?

Next: Application Structure — the Controller-Service-Repository pattern and how to organize packages.

Updated: