A simple Spring Boot web application demonstrating containerized deployment with Docker and Render.com integration.
- Features
- Technology Stack
- Quick Start
- Development
- Database Configuration
- Docker
- Deployment
- API Endpoints
- Project Structure
- Documentation
- Contributing
- License
- Links
- Contact
- Simple REST API with Spring Boot
- Database Integration with PostgreSQL (dev/prod) and H2 (testing)
- JPA/Hibernate ORM with automatic schema management
- Environment-based Configuration with multiple profiles
- Containerized with Docker multi-stage build
- Auto-deployment on Render.com
- PR Previews for testing changes
- Health checks and monitoring ready
- Production-optimized Docker image
- Automatic URL Ping Service to keep apps alive on free hosting
- Java 17 - Programming language
- Spring Boot 3.5.5 - Application framework
- Spring Data JPA - Database abstraction layer with Hibernate
- PostgreSQL - Primary database for development and production
- H2 Database - In-memory database for testing
- Maven 3.9.9 - Build tool
- Docker - Containerization
- Render.com - Cloud deployment platform
- Java 17 or later
- Maven 3.6+ (or use included wrapper)
- Docker (optional, for containerization)
# Clone the repository
git clone https://github.com/Abhay2133/hello_spring.git
cd hello_spring
# Run with Maven wrapper
make run
# Or manually
./mvnw spring-boot:runThe application will start on http://localhost:8080
# Build the project
make build
# Run the application
make run
# Run tests
make test
# Clean build artifacts
make clean
# Package as JAR
make package
# Database migrations
make migrate # Run pending migrations
make migrate-info # Show migration status
make migrate-create name=add_column # Create new migration
make migrate-validate # Validate migrations
# Docker commands
make docker-build # Build Docker image
make docker-run # Run container
make docker-push # Push to Docker Hub
make docker-stop # Stop container
# Deployment
make deploy # Deploy to Render.com
# Utility commands
make health # Check app health
make status # Show project status
make help # Show all commands# Compile and run
./mvnw clean spring-boot:run
# Run tests
./mvnw test
# Package JAR
./mvnw clean package
# Skip tests during build
./mvnw clean package -DskipTestsThis application uses PostgreSQL for development/production and H2 for testing with Hibernate as the ORM, and Flyway for database migrations.
π Detailed Documentation:
- Database Migrations Guide - Complete Flyway migration documentation
- Migration Quick Start - Get started with migrations quickly
-
Copy the environment template:
cp .env.example .env
-
Configure your database connection in
.env:# Application Profile (dev, test, prod) SPRING_PROFILES_ACTIVE=dev # PostgreSQL Database Configuration DATABASE_URL=jdbc:postgresql://localhost:5432/hello_spring DATABASE_USERNAME=postgres DATABASE_PASSWORD=your_password # JPA/Hibernate Configuration HIBERNATE_DDL_AUTO=update JPA_SHOW_SQL=true
- Uses PostgreSQL database
hibernate.ddl-auto=validate- Validates schema (Flyway manages changes)- SQL logging enabled for debugging
- Flyway auto-migration enabled
- Uses H2 in-memory database
hibernate.ddl-auto=create-drop- Creates fresh schema per test- Automatic cleanup after tests
- Uses PostgreSQL database
hibernate.ddl-auto=validate- Only validates existing schema- SQL logging disabled for performance
- Flyway migrations run automatically
-
Install PostgreSQL (using Docker):
docker run --name postgres-dev \ -e POSTGRES_DB=hello_spring \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=password \ -p 5432:5432 \ -d postgres:15
-
Or install locally:
- Ubuntu/Debian:
sudo apt install postgresql postgresql-contrib - macOS:
brew install postgresql - Windows: Download from postgresql.org
- Ubuntu/Debian:
-
Create database:
CREATE DATABASE hello_spring;
| Method | Endpoint | Description |
|---|---|---|
| POST | /users?username=john&email=john@example.com |
Create a new user |
| GET | /users |
Get all users |
| GET | /users/search?username=john |
Find user by username |
# Build image
make docker-build
# Run container
docker run -p 8080:8080 abhaybisht01/hello-spring:latest
# View logs
docker logs <container-id>- Base Image: Eclipse Temurin 17 JRE
- Build Image: Maven 3.9.9 with Eclipse Temurin 17
- Multi-stage: Optimized for production
- Security: Non-root user execution
- Health Check: Built-in health monitoring
This project is configured for automatic deployment on Render.com using Docker and GitHub Actions.
π Deployment Documentation: GitHub Actions Deployment Guide
- Auto-Deploy: Pushes to
mainbranch trigger deployment - PR Previews: Pull requests get preview URLs
- Health Checks: Automatic monitoring on
/endpoint - Environment: Containerized with Docker
-
Dockerfile Build (Current):
env: docker dockerfilePath: ./Dockerfile
-
Registry Image:
env: docker image: url: abhaybisht01/hello-spring:latest
PORT: Server port (default: 8080)JAVA_TOOL_OPTIONS: JVM optimization flags
| Method | Endpoint | Description | Response |
|---|---|---|---|
| GET | / |
Welcome message | "Greetings from Spring Boot!" |
| GET | /health |
Application health status | JSON with health info and ping status |
| GET | /ping-status |
Ping service status | JSON with ping configuration and stats |
# Test the main API
curl http://localhost:8080/
# Check application health
curl http://localhost:8080/health
# Check ping service status
curl http://localhost:8080/ping-status
# Response examples
curl http://localhost:8080/health
{
"status": "UP",
"message": "Hello Spring Boot is running",
"timestamp": 1694678400000,
"pingStatus": {
"enabled": true,
"url": "https://example.com",
"intervalMinutes": 5,
"totalPings": 42,
"lastResult": "SUCCESS - Response time: 234ms",
"lastPingTime": "2025-09-14 10:30:00"
}
}The application includes an automatic ping service to keep your app alive on free hosting services like Render.com that sleep inactive apps.
Set these environment variables:
# Enable ping service
PING_ENABLED=true
# URL to ping (usually your own app URL)
PING_URL=https://your-app.onrender.com
# Ping interval in minutes (default: 5)
PING_INTERVAL=5
# Log level for ping service (default: INFO)
PING_LOG_LEVEL=INFO- Configurable interval (default: 5 minutes)
- Automatic logging with timestamps and response times
- Error handling with retry logic
- Status monitoring via
/ping-statusendpoint - Health integration in
/healthendpoint
hello_spring/
βββ docs/ # π Documentation
β βββ DATABASE_MIGRATIONS.md # Database migration guide
β βββ MIGRATION_SETUP.md # Quick migration setup
β βββ DEPLOYMENT.md # Deployment configuration
βββ src/
β βββ main/
β β βββ java/
β β β βββ com/example/hello_spring/
β β β βββ HelloSpringApplication.java # Main application
β β β βββ AppConfig.java # Cache configuration
β β β βββ controllers/
β β β β βββ HelloController.java # REST endpoints
β β β βββ cron_jobs/
β β β β βββ PingService.java # Keep-alive service
β β β βββ entities/
β β β β βββ User.java # JPA entities
β β β βββ repositories/
β β β β βββ UserRepository.java # Data access
β β β βββ services/
β β β βββ UserService.java # Business logic
β β βββ resources/
β β βββ application.properties # Main configuration
β β βββ application-dev.properties # Dev config
β β βββ application-prod.properties # Prod config
β β βββ application-test.properties # Test config
β β βββ db/migration/ # Flyway migrations
β β β βββ V1__create_users_table.sql # Initial schema
β β βββ static/ # Static web content
β β βββ index.html
β β βββ css/style.css
β β βββ js/script.js
β βββ test/
β βββ java/
β βββ com/example/hello_spring/
β βββ HelloSpringApplicationTests.java # Tests
βββ target/ # Build output
βββ .mvn/wrapper/ # Maven wrapper
βββ Dockerfile # Docker configuration
βββ .dockerignore # Docker ignore rules
βββ render.yaml # Render.com config
βββ Makefile # Build automation
βββ pom.xml # Maven configuration
βββ README.md # This file
Comprehensive documentation is available in the docs/ directory:
| Document | Description | Link |
|---|---|---|
| Database Migrations | Complete guide to Flyway migrations, creating migrations, examples | DATABASE_MIGRATIONS.md |
| Migration Quick Start | Quick setup guide for getting started with migrations | MIGRATION_SETUP.md |
| Deployment Guide | GitHub Actions setup, Docker Hub, Render.com configuration | DEPLOYMENT.md |
- Spring Boot: Official Documentation
- Spring Data JPA: Reference Guide
- Flyway: Documentation
- PostgreSQL: Official Docs
- Docker: Get Started Guide
- Render.com: Documentation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Live Demo: [Deployed on Render.com]
- Docker Hub: abhaybisht01/hello-spring
- GitHub: Abhay2133/hello_spring
Abhay - @Abhay2133
Project Link: https://github.com/Abhay2133/hello_spring