A Spring Boot 3.3.5 application demonstrating custom Bean Validation annotations for a farm weather prediction domain.
Created by xjmaine.
- Java 17+
- Maven 3.9+
- MySQL 8.0+
# Create database
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS farm_weather;"
# Configure
cp application.example.properties src/main/resources/application.properties
# Edit with your MySQL credentials
# Run
mvn clean spring-boot:runSwagger UI: http://localhost:8081/api/v1/swagger-ui.html
| Annotation | Validates | Allowed Values |
|---|---|---|
@ValidSeason |
Farming season | DRY, RAINY, HARMATTAN |
@CropType |
Crop type | MAIZE, CASSAVA, COCOA, RICE, PLANTAIN, YAM, etc. |
@FarmRegion |
Ghana region | GREATER_ACCRA, ASHANTI, WESTERN, EASTERN, etc. |
@RecommendedAction |
Farm action | IRRIGATE, FERTILIZE, HARVEST, PLANT, etc. |
@FutureDate |
Date must be future | LocalDate, LocalDateTime |
@UniqueCropName |
DB uniqueness | Queries CropRepository |
| Annotation | Validates |
|---|---|
@CropSeasonMismatch |
Crop type is valid for the given season (cross-field) |
| Annotation | Behavior |
|---|---|
@AuditLog |
Logs method execution with timing via AuditLogAspect |
annotations/
├── pom.xml
├── application.example.properties
└── src/main/
├── java/io/web/farmweather/
│ ├── FarmWeatherApplication.java
│ ├── api/v1/controller/
│ │ ├── CropApi.java
│ │ ├── WeatherForecastApi.java
│ │ └── FarmAdviceApi.java
│ ├── domain/
│ │ ├── crop/ (entity, repo, service, DTOs)
│ │ ├── forecast/ (entity, repo, service, DTOs)
│ │ ├── advice/ (entity, repo, service, DTOs)
│ │ └── region/ (entity, repo)
│ └── global/
│ ├── annotation/ (8 custom annotations)
│ ├── validator/ (8 ConstraintValidator impls)
│ ├── aspect/ (AuditLogAspect)
│ ├── seeder/ (DataSeeder — loads from JSON)
│ ├── base/BaseEntity.java
│ ├── config/WebConfig.java
│ ├── exception/GlobalExceptionHandler.java
│ └── response/ApiResponse.java
└── resources/
├── application.properties
└── data/
├── regions.json (16 Ghana regions)
└── ai-responses.json (10 simulated AI advice entries)
44 source files. Each domain is self-contained (entity → repo → service → DTO → controller).
Java 17, Spring Boot 3.3.5, Spring Data JPA, MySQL 8.0, Hibernate 6.5 (@SQLRestriction), Hibernate Validator, Lombok, SpringDoc OpenAPI 2.6.0, Spring DevTools, Spring AOP.