A minimized Spring Boot application for processing course invitations using batch processing.
- Batch Processing: Process multiple email invitations efficiently using Spring Batch
- Email Service: Mock email service that logs email content (can be configured for real sending)
- Course Management: Basic CRUD operations for courses
- Invitation Management: Create, validate, and resend course invitations
- H2 Database: In-memory database for easy testing
- REST API: Simple REST endpoints for testing
- Multiple Email Processing: Fixed the issue where only one email was processed by properly parsing comma-separated email parameters in batch configuration
- Batch Configuration: Simplified and fixed the batch reader, processor, and writer components
- Exception Handling: Improved error handling and logging throughout the application
- Minimized Structure: Removed unnecessary components and simplified the architecture
- Java 17 or higher
- Maven 3.6 or higher
-
Navigate to the project directory:
cd /home/stark/dev/batch-processing -
Run the application:
mvn spring-boot:run
-
The application will start on
http://localhost:8080
The application automatically creates sample data:
- 2 courses (IDs: 1, 2)
- 3 users (students and a teacher)
curl -X POST http://localhost:8080/api/invitations/batch \
-H "Content-Type: application/json" \
-d '{
"courseId": 1,
"emails": ["test1@example.com", "test2@example.com", "test3@example.com"]
}'curl -X POST http://localhost:8080/api/invitations/single \
-H "Content-Type: application/json" \
-d '{
"courseId": 1,
"emails": ["test4@example.com", "test5@example.com"]
}'First, check the logs for the invitation code generated, then:
curl -X POST "http://localhost:8080/api/invitations/validate?invitationCode=ABC123&email=test1@example.com&courseId=1"curl -X POST http://localhost:8080/api/courses \
-H "Content-Type: application/json" \
-d '{
"title": "New Course",
"description": "A new course description",
"isPrivate": true
}'-
H2 Console: Available at
http://localhost:8080/h2-console- JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password: (empty)
- JDBC URL:
-
Logs: Check application logs for batch processing details and email content
By default, the application logs email content instead of sending real emails. To enable real email sending:
-
Set environment variables:
export MAIL_USERNAME=your-email@gmail.com export MAIL_PASSWORD=your-app-password
-
Uncomment the
mailSender.send(message)lines inEmailService.java
src/main/java/com/example/batch/
├── BatchProcessingApplication.java # Main application class
├── config/
│ ├── BatchConfiguration.java # Basic batch configuration
│ ├── DataInitializer.java # Sample data initialization
│ └── StudentInvitationBatchConfig.java # Batch job configuration
├── controller/
│ ├── CourseController.java # Course REST endpoints
│ └── InvitationController.java # Invitation REST endpoints
├── dto/
│ └── StudentInvitationRequest.java # Request DTO
├── model/
│ ├── Course.java # Course entity
│ ├── StudentCourseInvitation.java # Invitation entity
│ └── User.java # User entity
├── repository/
│ ├── CourseRepository.java # Course data access
│ ├── StudentCourseInvitationRepository.java # Invitation data access
│ └── UserRepository.java # User data access
├── service/
│ ├── CourseService.java # Course business logic
│ ├── EmailService.java # Email sending service
│ ├── InvitationBatchService.java # Batch job launcher
│ └── StudentCourseInvitationService.java # Invitation business logic
└── util/
└── CodeGenerator.java # Utility for generating codes
- Spring Boot 2.7.18: Compatible with Java 11
- Spring Batch: For processing multiple email invitations efficiently
- Spring Data JPA: For database operations with Hibernate
- H2 Database: In-memory database for development and testing
- REST API: Simple endpoints for testing and integration
- Batch Processing: Fixed to handle multiple emails correctly
- Fixed Multiple Email Processing: The main issue where only one email was processed is now resolved by properly parsing comma-separated email parameters in the batch configuration
- Java 11 Compatibility: Downgraded from Spring Boot 3.x to 2.7.18 and fixed text block syntax
- Minimized Structure: Removed unnecessary components and simplified the architecture
- Improved Error Handling: Centralized error handling with proper logging throughout the application
- Mock Email Service: Easy to test without requiring real email configuration - logs email content instead
- Automatic Sample Data: Ready-to-use test data (2 courses, 3 users) created on startup
- Fixed Batch Configuration: Properly handles comma-separated emails and processes them in chunks
- Enhanced Logging: Better visibility into batch processing steps and email sending
Run the automated test script:
./test-batch-processing.shThis script will:
- Start the application
- Test all REST endpoints
- Verify batch processing functionality
- Confirm multiple email processing works correctly
- Show application logs
- Clean up automatically