Spaces:
No application file
No application file
Spring Boot Application for Hugging Face Spaces
A simple Spring Boot REST API application designed to be deployed on Hugging Face Spaces.
Features
- REST API with multiple endpoints
- Health check endpoint for monitoring
- Containerized with Docker
- Configured for Hugging Face Spaces deployment (port 7860)
API Endpoints
GET /api/
Returns a welcome message with current status.
Response:
{
"message": "Welcome to Spring Boot on Hugging Face!",
"status": "running",
"timestamp": "2024-11-13T10:30:00"
}
GET /api/greeting
Returns a personalized greeting.
Parameters:
name(optional): Name for the greeting (default: "World")
Example: /api/greeting?name=John
Response:
{
"greeting": "Hello, John!",
"timestamp": "2024-11-13T10:30:00"
}
GET /api/health
Health check endpoint.
Response:
{
"status": "UP",
"service": "Spring Boot Demo"
}
POST /api/echo
Echoes back the received JSON payload.
Request Body:
{
"message": "test",
"data": "example"
}
Response:
{
"received": {
"message": "test",
"data": "example"
},
"timestamp": "2024-11-13T10:30:00"
}
Local Development
Prerequisites
- Java 17 or higher
- Maven 3.6 or higher
Running Locally
- Clone the repository
- Navigate to the project directory
- Run the application:
mvn spring-boot:run - Access the application at
http://localhost:7860/api/
Building the JAR
mvn clean package
Running with Docker
# Build the Docker image
docker build -t springboot-hf-demo .
# Run the container
docker run -p 7860:7860 springboot-hf-demo
Deploying to Hugging Face Spaces
Create a new Space on Hugging Face
Choose "Docker" as the SDK
Upload these files to your Space repository:
Dockerfilepom.xmlsrc/directory with all Java files and resourcesREADME.md
The Space will automatically build and deploy your application
Hugging Face Configuration
The application is configured to:
- Listen on port 7860 (required by Hugging Face)
- Bind to all network interfaces (0.0.0.0)
- Run as a non-root user for security
Project Structure
springboot-app/
βββ src/
β βββ main/
β βββ java/
β β βββ com/example/demo/
β β βββ DemoApplication.java
β β βββ controller/
β β βββ GreetingController.java
β βββ resources/
β βββ application.properties
βββ Dockerfile
βββ pom.xml
βββ README.md
Technologies Used
- Spring Boot 3.2.1
- Java 17
- Maven
- Docker
- Spring Web
- Spring Boot Actuator
License
This project is open source and available for educational purposes.
Contributing
Feel free to fork this project and customize it for your needs!