Skip to main content

MODULE 2 - Getting Started with Spring Boot

Module Objectives​

This module will enable you to:

  • Master the use of Spring Initializr to create projects
  • Understand the structure of a Spring Boot project
  • Set up your development environment (Visual Studio Code)
  • Create your first REST application
  • Use basic Spring Boot annotations

Module Content​

Theory​

Chapter 1: Spring Initializr​

  • What is Spring Initializr
  • Project configuration (Maven, Java, Spring Boot)
  • Metadata and parameters
  • Dependency and starter management
  • Project generation and import
  • Alternatives (CLI, API, IDE)

Chapter 2: Structure of a Spring Boot Project​

  • Complete project tree
  • Role of the pom.xml file
  • Package organization (Controller, Service, Repository, Model)
  • Resources directories (static, templates)
  • Configuration with application.properties/yml
  • Naming conventions

Chapter 3: Configuration​

  • application.properties and application.yml files
  • Common Spring Boot properties
  • Database configuration
  • Log configuration
  • Custom properties with @Value and @ConfigurationProperties
  • Profile management (dev, test, prod)
  • Environment variables and security

Chapter 4: Basic Annotations​

  • @SpringBootApplication and its components
  • Stereotype annotations: @Component, @Service, @Repository
  • @RestController vs @Controller
  • HTTP mapping annotations: @GetMapping, @PostMapping, @PutMapping, @DeleteMapping
  • @RequestParam, @PathVariable, @RequestBody
  • Dependency injection with @Autowired

Chapter 5: Introduction to Repositories​

  • What is a Spring Data JPA Repository
  • The 4 basic methods inherited from JpaRepository
  • Simple naming conventions: findBy, And, Or
  • Create a JPA entity
  • Complete architecture Controller → Service → Repository
  • Practical examples with the User entity
  • Note: Simplified content for beginners. Advanced concepts (joins, JPQL, @Query) will be covered in Module 6

Practical Work​

TP2.1: Greeting Application with VS Code​

Objective: Create your first Spring Boot REST application

Content:

  • Spring Initializr configuration
  • Project import into Visual Studio Code
  • Creation of a simple REST controller
  • Testing and debugging
  • Troubleshooting common issues

Estimated Duration: 2-3 hours

Prerequisites: JDK 17+, Maven, VS Code with Java extensions

Level: Beginner


TP2.2: H2 Database - In-Memory and Persistence​

Objective: Master H2 in in-memory mode and persistent file mode

Content:

  • Part 1: In-memory H2 (temporary data)
  • Part 2: Persistent H2 (data on disk)
  • Part 3: Advanced management with file renaming
  • Differences between modes
  • Configuration of schema.sql and data.sql
  • H2 console
  • 4 practical exercises
  • Use of the 4 basic JPA methods (findById, findAll, save, deleteById)

Estimated Duration: 3-4 hours

Prerequisites: TP2.1 completed, Chapter 5 (Repositories) read

Level: Beginner


📚 Important Note: Pedagogical Restructuring​

Where are TP3 and TP4?​

If you are looking for advanced TPs, they have been moved to the appropriate modules for better pedagogical progression:

TP3.1: CRUD Architecture → MODULE 3​

  • New name: TP3.1 of Module 3
  • Reason: Uses advanced concepts (Validation, ResponseEntity, Error Handling)
  • Added prerequisites:
    • Chapter 1: Service Layer in detail
    • Chapter 2: Data Validation
    • Chapter 3: HTTP Error Handling
    • Chapter 4: Professional 3-layer Architecture

TP4.1: PostgreSQL → MODULE 4​

  • New name: TP4.1 of Module 4
  • Reason: Uses production concepts (PostgreSQL, Lombok, Jakarta, DDL strategies)
  • Added prerequisites:
    • Chapter 1: PostgreSQL - Installation and configuration
    • Chapter 2: Jakarta vs Javax Persistence
    • Chapter 3: Hibernate and DDL strategies
    • Chapter 4: Lombok

Why This Change?​

Pedagogical analysis:

TP3 (formerly here): 60% of concepts not taught
TP4 (formerly here): 80% of concepts not taught

Positive impact:

  • ✅ Each TP now has ALL the necessary theory BEFORE starting it
  • ✅ Less frustration and confusion
  • ✅ More progressive and effective learning
  • ✅ Better preparation for production
MODULE 2 (Basics)
├── 5 Theoretical Chapters
└── 2 Practical TPs (TP2.1, TP2.2)
↓
MODULE 3 (Robust Architecture)
├── 4 Theoretical Chapters
└── 1 TP (CRUD Architecture) ← Former TP3 of Module 2
↓
MODULE 4 (Production)
├── 4 Theoretical Chapters
└── 1 TP (PostgreSQL) ← Former TP4 of Module 2

Technical Prerequisites​

Before starting this module, make sure you have:

Required Software​

  1. JDK 17 or higher

  2. Visual Studio Code

  3. VS Code Extensions:

    • Extension Pack for Java (Microsoft)
    • Spring Boot Extension Pack (VMware)
    • Maven for Java (Microsoft)
  4. Maven 3.9+

Installation Verification​

# Verify Java
java -version

# Verify Maven
mvn -version

Estimated Duration​

Theory: 6-8 hours (5 chapters)
Practice: 5-7 hours (TP2.1, TP2.2)
Total: 11-15 hours (2-3 sessions of 4-6 hours)

Note: Module 2 has been simplified to focus on the fundamentals. Advanced TPs (CRUD Architecture, PostgreSQL) are now in Modules 3 and 4 with the appropriate theory.


Additional Resources​

Official Documentation​


Success Criteria​

By the end of this module, you should be able to:

  • ✅ Create a Spring Boot project with Spring Initializr
  • ✅ Configure Visual Studio Code for Java/Spring development
  • ✅ Create and test a simple REST controller
  • ✅ Understand the structure of a Spring Boot project
  • ✅ Configure application.properties and application.yml
  • ✅ Use basic annotations (@RestController, @Service, @Repository)
  • ✅ Create simple JPA entities
  • ✅ Use the 4 basic CRUD methods (findById, findAll, save, deleteById)
  • ✅ Create simple search methods (findBy, And, Or)
  • ✅ Work with H2 in in-memory and persistent mode

What you are NOT yet expected to master (this is in the following modules):

  • ❌ Complete 3-layer architecture (Module 3)
  • ❌ Advanced validation (Module 3)
  • ❌ HTTP error handling (Module 3)
  • ❌ PostgreSQL in production (Module 4)
  • ❌ Lombok (Module 4)
  • ❌ JPA joins (Module 6)

Next Steps​

Once this module is completed, you will be ready for:

  • Module 3: Layered Architecture and Complete CRUD

    • In-depth Service Layer
    • Data Validation (@Valid, @NotNull, @Size, etc.)
    • HTTP Error Handling (ResponseEntity, status codes)
    • Professional 3-layer Architecture
    • TP3.1: CRUD Architecture (moved for better progression)
  • Module 4: Databases in Production

    • PostgreSQL - Installation and configuration
    • Jakarta vs Javax Persistence
    • Hibernate and DDL strategies
    • Lombok to reduce code
    • TP4.1: PostgreSQL Migration (moved for better progression)
  • Module 5: Spring Core - Advanced IoC and DI

  • Module 6: Advanced Spring Data JPA (Joins, JPQL, Optimization)

📚 Why This Reorganization?​

Old structure:

  • Module 2 contained 4 TPs, 2 of which were too advanced
  • TP3.1 and TP4.1 used concepts not taught
  • Student frustration

New structure:

  • ✅ Module 2: Basics only (TP2.1, TP2.2)
  • ✅ Module 3: CRUD with complete theory (TP3.1)
  • ✅ Module 4: Production with complete theory (TP4.1)

💡 Result: Each TP now has ALL the necessary theory BEFORE starting it!


Start with TP2.1