A modern Java REST API server following best practices with Spring Boot, comprehensive testing, and code quality tools.
- π RESTful API server using Spring Boot 3
- β Comprehensive unit tests with JUnit 5
- π Code quality tools: Checkstyle, SpotBugs, PMD
- π Code coverage reporting with JaCoCo
- π¦ Modern project structure following Java best practices
- π§ Makefile for common development tasks
- β‘ Built-in validation and error handling
.
βββ src/
β βββ main/
β β βββ java/com/aaronsun/java/
β β β βββ JavaApiServerApplication.java # Application entry point
β β β βββ internal/
β β β βββ api/ # REST controllers
β β β βββ models/ # Data models
β β βββ resources/
β β βββ application.properties # Application configuration
β βββ test/
β βββ java/com/aaronsun/java/ # Test classes
βββ pom.xml # Maven configuration
βββ checkstyle.xml # Checkstyle rules
βββ Makefile # Build automation
βββ README.md # This file
- Java 21 or later
- Maven 3.8 or later
- Make (optional, for using Makefile)
make install
# or
mvn clean install -DskipTestsmake run
# or
mvn spring-boot:runThe server will start on http://localhost:8080 by default.
make build
# or
mvn clean package -DskipTestsThe JAR file will be created at target/java-api-server-1.0.0.jar.
make test
# or
mvn testmake test-coverage
# or
mvn clean test jacoco:reportCoverage report will be available at target/site/jacoco/index.html.
make lintmake lint-checkstyle # Run Checkstyle
make lint-spotbugs # Run SpotBugs
make lint-pmd # Run PMDOr using Maven directly:
mvn checkstyle:check # Checkstyle
mvn spotbugs:check # SpotBugs
mvn pmd:check # PMDGET /health
Returns the health status of the service.
Response:
{
"status": "ok",
"service": "java-api-server"
}GET /api/v1/users
Response:
{
"data": [
{
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
]
}GET /api/v1/users/:id
Response:
{
"data": {
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
}POST /api/v1/users
Content-Type: application/json
{
"name": "John Doe",
"email": "[email protected]"
}
Response:
{
"data": {
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
}DELETE /api/v1/users/:id
Response:
{
"message": "User deleted"
}PORT: Server port (default: 8080)ENV: Environment mode (development/production, default: development)
Run make help to see all available commands:
make build- Build the applicationmake run- Run the applicationmake run-jar- Build and run the application JARmake test- Run testsmake test-coverage- Run tests with coverage reportmake lint- Run all lintersmake lint-checkstyle- Run Checkstylemake lint-spotbugs- Run SpotBugsmake lint-pmd- Run PMDmake clean- Clean build artifactsmake install- Install dependenciesmake verify- Verify the project (compile, test, checkstyle, etc.)make ci- Run CI checks (lint + test)
This project includes several code quality tools:
Checks code style and formatting. Configuration is in checkstyle.xml.
Static analysis tool to find bugs. Configured in pom.xml.
Source code analyzer that finds common programming flaws. Configured in pom.xml.
Code coverage tool. Minimum coverage threshold is set to 80%.
- Follow Google Java Style Guide guidelines
- Ensure
make lintpasses before committing - Write tests for new features
- All tests should be in
*Test.javaor*Tests.javafiles - Use JUnit 5 for unit tests
- Use MockMvc for controller tests
- Aim for >80% test coverage
mvn clean package -DskipTests
java -jar target/java-api-server-1.0.0.jarMIT