How sdeleuze/petclinic-efficient-container works
Project type and purpose
• This is a full-stack, monolithic Spring Boot web application (“Spring Petclinic”) repurposed to demonstrate containerization and runtime-efficiency improvements when migrating from Spring Boot 2/Java 8 to Spring Boot 3/Java 21.
• It includes a traditional MVC web UI (Thymeleaf), REST endpoints, a persistence layer with Spring Data JDBC and caching, all packaged and deployed via Docker & Docker Compose.
Main components
a. Client layer
• Browser – renders Thymeleaf pages and consumes JSON endpoints
• Benchmark tool (Oha) – external load-testing client
b. Application layer (single Spring Boot container)
• Controllers (e.g., OwnerController, VetController, VisitController, CrashController)
• View engine (Thymeleaf templates + static resources)
• Service & caching (annotated @Cacheable on VetRepository)
• Persistence (Spring Data JDBC repositories connecting over JDBC)
• Configuration (application.properties, CacheConfiguration)
c. Data layer
• PostgreSQL container – initialized via sql/1-schema-postgres.sql & sql/2-data-postgres.sql
d. Build & deployment pipeline
• Maven wrapper & pom.xml – compile, test, package
• Dockerfile & build-container-image.sh – multi-stage image build using self-extracting JAR
• Docker Compose – orchestrates Petclinic and Postgres services
Relationships and interactions
• Browser → (HTTP/HTTPS) → Spring Boot App: requests for HTML (Thymeleaf) or JSON
• Spring Boot App → (JDBC) → PostgreSQL: CRUD operations
• Spring Boot App → (in-memory cache) → cached Vet data
• Maven → builds → JAR → Docker image → run by Docker Compose
• Oha → (HTTP) → endpoints for benchmarking
Architectural patterns & principles
• Layered MVC: presentation (controllers + views), business/validation, persistence
• Container-first deployment: immutable build artifacts, self-extracting executable JAR
• Infrastructure as Code: docker-compose defines networking, resource limits (2 CPU, 2 GB RAM)
• Cache-aside pattern for frequently accessed data (vets)