Skip to content

Spring Batch 5 skeleton for Spring Boot 3. Includes DB to CSV and CSV to DB samples for quick customization. This repository demonstrates multi-database setup, efficient batch processing, and GitHub Actions integration for CI/CD pipelines.

License

Notifications You must be signed in to change notification settings

kinto-technologies/SpringBoot3BatchStarter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6be323f Β· Dec 28, 2024
Dec 24, 2024
Dec 28, 2024
Dec 11, 2024
Dec 12, 2024
Dec 27, 2024
Dec 11, 2024
Dec 13, 2024
Dec 28, 2024
Dec 28, 2024
Dec 21, 2024
Dec 6, 2024
Dec 6, 2024
Dec 27, 2024

Repository files navigation

Spring Batch 5 Starter

Accelerate Your Spring Boot 3 Batch Development πŸš€

GitHub stars Build codecov Java 21 License: Apache 2.0

🌐 Language Support

πŸ‡―πŸ‡΅ ζ—₯本θͺžη‰ˆ README は こけら.

πŸ“‹ Requirements

  • JDK 21 (automatically downloaded by Gradle toolchain)
  • Docker Desktop
  • Gradle 8.5+ (not required if using gradlew)

πŸ’‘ This project uses JDK 21, but thanks to Gradle's toolchain feature, it will be automatically downloaded even if not installed locally.

πŸ” Overview

This comprehensive starter kit is designed specifically for Spring Boot 3 and Spring Batch 5, providing a production-ready foundation for enterprise batch processing applications. It offers two main components:

Skeleton Batch

A minimal, ready-to-use batch application where you can:

  • Start development immediately by adding your business logic
  • Focus on implementation without complex configuration
  • Run in any environment with H2 in-memory database

DB and CSV Batch

A practical example implementing common batch operations:

  • Export data from database to CSV with customizable queries
  • Import CSV data to database with efficient bulk operations
  • Demonstrate multi-database configuration best practices

Both components are built with industry best practices and utilize the latest Spring framework features to accelerate your batch development process.

πŸš€ Quick Start Guide

1️⃣ Try Skeleton Batch

# Clone repository
git clone https://github.com/kinto-technologies/SpringBoot3BatchStarter.git

# Build and Run
./gradlew :skeletonBatch:bootRun

2️⃣ Try DB and CSV Batch

# Start MySQL container
docker compose up -d

# Run DB to CSV export
./gradlew :dbAndCsvBatch:bootRun --args="--spring.batch.job.name=DB_TO_CSV --spring.profiles.active=local"

# Run CSV to DB import
./gradlew :dbAndCsvBatch:bootRun --args="--spring.batch.job.name=CSV_TO_DB --spring.profiles.active=local"

πŸ“ Project Structure

.
β”œβ”€β”€ gradlew                # Gradle wrapper
β”œβ”€β”€ settings.gradle
β”œβ”€β”€ compose.yaml           # Docker Compose configuration
β”œβ”€β”€ init-scripts           # Database initialization
β”‚   β”œβ”€β”€ 1-create-table.sql
β”‚   └── 2-insert-data.sql
β”œβ”€β”€ dbAndCsvBatch          # DB-CSV batch project
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ build.gradle
β”‚   └── src/
└── skeletonBatch          # Skeleton batch project
    β”œβ”€β”€ README.md
    β”œβ”€β”€ build.gradle
    └── src/

πŸ’‘ Core Features

πŸ—οΈ Foundation Components

  • Production-Ready Batch Framework:
    • Pre-configured skeleton structure
    • Ready for immediate development
    • H2 in-memory database for simple setup

πŸ”„ Data Operations

  • DB to CSV Export:
    • Dynamic query support
    • Configurable data extraction
  • CSV to DB Import:
    • Bulk insert operations
    • High-performance data loading

πŸ› οΈ Technical Stack

  • Spring Integration:
    • Spring Batch job/step management
    • Type-safe SQL with jOOQ
    • CSV processing with OpenCSV
  • Dual Database Setup:
    • H2 for batch metadata
    • MySQL for business data

πŸ’» Development Tools

  • Dynamic Configuration:
    • Environment profiles (local/server)
    • Runtime job configuration
    • Customizable queries
  • Development Support:
    • Hot reload support
    • Debug configuration
    • IDE integration

πŸ” Quality Assurance

  • Code Quality:
    • Google Java Format (Spotless)
    • Static analysis (SpotBugs)
    • Test coverage (Jacoco)
  • CI Pipeline:
    • GitHub Actions integration
    • Automated testing
    • Quality gates

❓ Troubleshooting

Entity Classes Not Found

  • Cause: jOOQ auto-generation not executed
  • Solution: Run ../gradlew generateJooq
  • Alternative: Copy from build/generated-src/jooq to src/main/java

Database Connection Error

  • Cause: MySQL container not running
  • Solution: Run docker compose up -d
  • Verify: Check with docker ps

Multiple Jobs Error

  • Symptom: "Job name must be specified" error
  • Cause: Job name required when multiple jobs exist
  • Solution: Add --spring.batch.job.name=DB_TO_CSV

πŸ”„ Continuous Integration

GitHub Actions

  • Automated build and test
  • Code formatting check
  • Static analysis
  • Coverage measurement

Codecov

  • Coverage visualization
  • Automatic PR reports
  • Change tracking

Workflow

  1. Triggers on push/pull request
  2. Sets up MySQL container
  3. Configures JDK 21
  4. Runs Gradle build and tests
  5. Uploads coverage reports

πŸ“Œ Version Information

  • Spring Boot: 3.4.1
  • Spring Dependency Management: 1.1.7
  • Spotless (Google Java Format): 6.22.0
  • jOOQ: 9.0
  • OpenCSV: 5.9
  • SpotBugs: 6.0.27

πŸ“œ License

Licensed under the Apache License 2.0.

Copyright Β© 2024 KINTO Technologies Corporation