Skip to content

About

A basic springboot app for weather prediction and farmer advice

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Farm Weather

A Spring Boot 3.3.5 application demonstrating custom Bean Validation annotations for a farm weather prediction domain.

Created by xjmaine.

Prerequisites

  • Java 17+
  • Maven 3.9+
  • MySQL 8.0+

Quick Start

# 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:run

Swagger UI: http://localhost:8081/api/v1/swagger-ui.html

Custom Annotations

Bean Validation (field-level)

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

Bean Validation (class-level)

Annotation Validates
@CropSeasonMismatch Crop type is valid for the given season (cross-field)

AOP (method-level)

Annotation Behavior
@AuditLog Logs method execution with timing via AuditLogAspect

Project Structure

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).

Tech Stack

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.

Documentation

License

Apache License 2.0

About

A basic springboot app for weather prediction and farmer advice

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages