Skip to content

Add Spring Boot Code Samples to Starter Solution #31

@shawnewallace

Description

@shawnewallace

Description

Create src-springboot/ directory with Spring Boot equivalent of the TaskManager solution for workshop reference.

Acceptance Criteria

  • Create src-springboot/ directory structure
  • Implement TaskManager API in Spring Boot
  • Follow Clean Architecture pattern
  • Include Repository pattern examples
  • Add Spring Data JPA entities
  • Include comprehensive tests (JUnit 5 + Mockito)
  • Add integration tests with Testcontainers (H2 used with PostgreSQL compatibility)
  • Include OpenAPI documentation
  • Add Maven and Gradle build files (Maven complete, Gradle optional/skipped)
  • Mirror .NET solution structure for easy comparison

Implementation Summary

Completed on: March 31, 2026
Branch: feature/epic-16-spring-boot-adaptation
Commits: 20 commits with systematic implementation

What Was Built

4-Module Clean Architecture Implementation:

  • taskmanager-domain - Pure Java domain model (Task, TaskId, TaskStatus, TaskRepository interface)
  • taskmanager-application - Use case orchestration (TaskService with @transactional)
  • taskmanager-infrastructure - JPA persistence (TaskEntity, mapper, Spring Data repository)
  • taskmanager-api - REST endpoints (TaskController, DTOs, GlobalExceptionHandler, OpenAPI)

Statistics:

  • 22 Java files, 3,604 lines of code
  • 102 tests, 100% pass rate
  • 72.55% code coverage (exceeds 70% threshold)
    • Domain: 79.94% (36 tests)
    • Application: 100% (33 tests)
    • Infrastructure: 44.05% (25 tests)
    • API: 82.89% (8 integration tests)

Key Features:

  • 8 REST endpoints with full CRUD + state transitions
  • OpenAPI/Swagger UI documentation
  • 4 Spring profiles (base, dev, prod, test)
  • H2 integration tests (PostgreSQL compatibility mode)
  • RFC 7807 error handling
  • Actuator monitoring endpoints

Documentation:

  • Comprehensive README.md with quick start, API docs, testing guide
  • coverage-summary.txt with detailed metrics
  • OpenAPI documentation at /swagger-ui.html

Project Structure

src-springboot/
├── pom.xml (Maven) ✅
├── README.md ✅
├── coverage-summary.txt ✅
├── taskmanager-domain/
│   ├── src/main/java/com/example/taskmanager/domain/tasks/
│   │   ├── Task.java (aggregate root)
│   │   ├── TaskId.java (record value object)
│   │   ├── TaskStatus.java (enum)
│   │   └── TaskRepository.java (port interface)
│   └── src/test/java/ (36 unit tests)
├── taskmanager-application/
│   ├── src/main/java/com/example/taskmanager/application/services/
│   │   └── TaskService.java (10 methods with @Transactional)
│   └── src/test/java/ (33 unit tests with Mockito)
├── taskmanager-infrastructure/
│   ├── src/main/java/com/example/taskmanager/infrastructure/persistence/
│   │   ├── entities/TaskEntity.java
│   │   ├── mappers/TaskMapper.java (anti-corruption layer)
│   │   └── repositories/
│   │       ├── SpringDataTaskRepository.java
│   │       └── JpaTaskRepositoryAdapter.java
│   └── src/test/java/ (25 tests: 12 mapper + 13 integration)
└── taskmanager-api/
    ├── src/main/java/com/example/taskmanager/api/
    │   ├── controllers/TaskController.java (8 REST endpoints)
    │   ├── dto/ (CreateTaskRequest, UpdateTaskRequest, TaskResponse)
    │   ├── exception/GlobalExceptionHandler.java
    │   ├── config/OpenApiConfig.java
    │   └── TaskManagerApplication.java
    ├── src/main/resources/
    │   ├── application.yml
    │   ├── application-dev.yml
    │   ├── application-prod.yml
    │   └── application-test.yml
    └── src/test/java/ (8 API integration tests)

Key Components

1. Domain Layer ✅

  • Task entity with rich business logic and state machine
  • TaskId as strongly-typed ID (Java record)
  • TaskRepository interface with 10 business-intent methods
  • 36 comprehensive unit tests

2. Application Layer ✅

  • TaskService with 10 use case methods
  • @transactional boundary management
  • 33 unit tests with Mockito

3. Infrastructure Layer ✅

  • JPA entity mappings (TaskEntity)
  • TaskMapper for domain/entity translation
  • Spring Data JPA repository implementation
  • H2 in-memory database for tests (PostgreSQL compatibility mode)
  • 25 tests (mapper + integration)

4. API Layer ✅

  • REST controllers with 8 endpoints
  • Request/Response DTOs (records with validation)
  • GlobalExceptionHandler with RFC 7807 Problem Details
  • OpenAPI documentation (Springdoc)
  • 8 full-stack integration tests

5. Tests ✅

  • 102 total tests, 0 failures
  • 72.55% overall coverage (exceeds 70% requirement)
  • H2 integration tests (Testcontainers not used due to Docker limitation in devcontainer)
  • Repository tests with actual database
  • API contract tests with @SpringBootTest

Configuration Files

application.yml ✅

  • PostgreSQL datasource with HikariCP
  • JPA/Hibernate configuration
  • Jackson JSON serialization
  • Actuator endpoints (health, metrics, prometheus)
  • Springdoc OpenAPI paths
  • Comprehensive logging

Profiles ✅

  • dev: Verbose logging, auto-schema updates, all actuator endpoints
  • prod: Environment variables, minimal logging, restricted endpoints
  • test: H2 in-memory, random port, minimal output

pom.xml (Maven) ✅

  • Spring Boot 3.2.4
  • Java 21 LTS
  • Spring Data JPA
  • PostgreSQL driver (runtime)
  • H2 (test scope)
  • Lombok
  • JUnit 5 + Mockito
  • Springdoc OpenAPI 2.3.0
  • JaCoCo coverage plugin

Documentation ✅

README.md includes:

  • Architecture overview with layer diagrams
  • Quick start guide
  • Build instructions (mvn clean install)
  • Run instructions (mvn spring-boot:run)
  • Test instructions (mvn test, mvn jacoco:report)
  • API documentation (Swagger UI)
  • Configuration guide for all profiles
  • Testing strategy explanation
  • Coverage metrics
  • Technology stack

DevContainer Integration ✅

Updated devcontainers to build Spring Boot on creation:

  • maintainer/devcontainer.json - Builds both .NET and Spring Boot
  • springboot-participant/devcontainer.json - Builds Spring Boot only

API Endpoints

Method Endpoint Description
POST /api/tasks Create a new task
GET /api/tasks List all tasks
GET /api/tasks/{id} Get task by ID
PATCH /api/tasks/{id} Update task (partial)
PUT /api/tasks/{id}/start Start task (PENDING → IN_PROGRESS)
PUT /api/tasks/{id}/complete Complete task (→ COMPLETED)
PUT /api/tasks/{id}/cancel Cancel task (→ CANCELLED)
DELETE /api/tasks/{id} Delete task

Related Issues

Notes

  • Gradle build was marked as optional (Maven is primary build tool)
  • Testcontainers replaced with H2 PostgreSQL compatibility mode due to Docker limitations in devcontainer
  • Infrastructure coverage (44%) is lower due to JPA boilerplate, but integration tests verify full functionality
  • All code committed and pushed to feature/epic-16-spring-boot-adaptation branch
  • Ready for PR review and merge

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions