Spring Boot

Article 3: Understanding Spring Boot Project Structure

By Utility Zone · 2026-01-27T18:30:13.617716

1. Introduction

Now that your Spring Boot application runs successfully, it’s time to understand what was generated.

Many beginners skip this step and get confused later. This article explains the Spring Boot project structure clearly and practically.


2. Default Project Structure

After creating a Spring Boot project, you’ll see something like this:

demo
 ├── src
 │   ├── main
 │   │   ├── java
 │   │   │   └── com.example.demo
 │   │   │       └── DemoApplication.java
 │   │   └── resources
 │   │       ├── application.properties
 │   │       └── static / templates
 │   └── test
 │       └── java
 ├── pom.xml
 └── mvnw / mvnw.cmd

Each part has a clear responsibility.


3. The DemoApplication.java File

@SpringBootApplication
public class DemoApplication {

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

3.1 What is @SpringBootApplication?

This single annotation combines:

  • @Configuration
  • @EnableAutoConfiguration
  • @ComponentScan

👉 This is why Spring Boot needs very little configuration.

3.2 What Happens at Startup?

When the app starts:

  1. Spring context is created
  2. Beans are scanned
  3. Auto-configuration is applied
  4. Embedded server starts

4. src/main/java – Application Code

This is where:

  • Controllers live
  • Services live
  • Repositories live

Recommended Package Structure

com.example.demo
 ├── controller
 ├── service
 ├── repository
 └── model

👉 Keeping this structure avoids messy code later.


5. src/main/resources – Configuration & Static Files

5.1 application.properties

This is the main configuration file.

Example:

server.port=8081
spring.application.name=demo-app

You’ll use this file heavily.


5.2 application.yml

Alternative to .properties.

Example:

server:
  port: 8081
spring:
  application:
    name: demo-app

Choose one, not both.


5.3 static Folder

Used for:

  • HTML
  • CSS
  • JS

Example:

/static/index.html

Accessible at:

http://localhost:8081/index.html

5.4 templates Folder

Used with:

  • Thymeleaf
  • FreeMarker

Mainly for server-side rendered apps.


6. pom.xml – Dependency & Build Configuration

This is the heart of Maven.

Key sections:

  • <dependencies>
  • <build>
  • <plugins>

Example:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

👉 Starters pull in multiple compatible libraries automatically.


7. src/test – Testing Code

This folder contains:

  • Unit tests
  • Integration tests

Example test:

@SpringBootTest
class DemoApplicationTests {

    @Test
    void contextLoads() {
    }
}

We’ll cover testing in detail later.


8. Maven Wrapper (mvnw)

Why it exists:

  • Ensures same Maven version for all developers
  • No need to install Maven manually

Use:

./mvnw clean install

9. Common Beginner Mistakes

❌ Putting all classes in one package
❌ Editing generated files blindly
❌ Mixing .properties and .yml

✔ Follow the structure ✔ Keep things organized


10. What You Should Understand Before Moving On

You should now clearly know:

  • What each folder is for
  • What @SpringBootApplication does
  • Where to put controllers, services, configs
  • Why Maven & pom.xml matter

11. What’s Next?

➡ Article 4: Building Your First REST API

  • @RestController
  • @GetMapping
  • Returning JSON
  • Testing APIs