Hackforge Academy

Category: java

Spring Boot project structure

Published on 02 Apr 2026

Explanation

The main class is the entry point of the Spring Boot application. It contains the @SpringBootApplication annotation and starts the embedded server using SpringApplication.run().

Code:

src/main/java/com/example/demo/
DemoApplication.java

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

Explanation

The controller layer handles HTTP requests from clients and returns responses. It uses annotations like @RestController and @RequestMapping.

Code:

src/main/java/com/example/demo/controller/
UserController.java

@RestController
@RequestMapping("/users")
public class UserController {

  @GetMapping
  public String getUsers() {
    return "List of users";
  }
}

Explanation

The service layer contains business logic. It acts as a bridge between controller and repository layers.

Code:

src/main/java/com/example/demo/service/
UserService.java

@Service
public class UserService {

  public String getUserServiceMessage() {
    return "Business logic executed";
  }
}

Explanation

The repository layer interacts with the database. It usually extends JpaRepository to perform CRUD operations.

Code:

src/main/java/com/example/demo/repository/
UserRepository.java

@Repository
public interface UserRepository extends
 JpaRepository<User, Long> {
}

Explanation

The resources folder contains configuration files like
application.properties
static files
template files required for the application.

Code:

src/main/resources/
 ├── application.properties
 ├── static/
 └── templates/

🚀 Learn Spring Boot with real-world projects

💡 Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
⚛️

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community