A Spring Boot REST API for user management with OpenAPI documentation.
- Spring Boot: 3.4.3
- H2 Database: 2.3.232
- SpringDoc OpenAPI: 2.8.0
- Spring Data JPA: 3.4.3
- Maven: 3.9.0
- Create, read, update, and delete users
- Validation for user data
- Exception handling with appropriate HTTP status codes
- OpenAPI documentation
- In-memory H2 database
- Java 17 or higher
- Maven 3.8.0 or higher
- Clone the repository
- Navigate to the project directory
- Run the application using Maven:
./mvnw spring-boot:runThe application will start on port 8081.
- API Base URL: http://localhost:8081/api/users
- OpenAPI Documentation: http://localhost:8081/swagger-ui.html
- OpenAPI JSON: http://localhost:8081/api-docs
- H2 Console: http://localhost:8081/h2-console
POST /api/users
Request body:
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "1234567890"
}GET /api/users
GET /api/users/{id}
PUT /api/users/{id}
Request body:
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "1234567890"
}DELETE /api/users/{id}
The application uses an H2 in-memory database with the following configuration:
- URL: jdbc:h2:mem:testdb
- Username: sa
- Password: password
src/main/java/com/example/usermanagement/
├── controller/
│ └── UserController.java
├── dto/
│ └── UserDTO.java
├── exception/
│ ├── GlobalExceptionHandler.java
│ ├── ResourceNotFoundException.java
│ └── UserAlreadyExistsException.java
├── model/
│ └── User.java
├── repository/
│ └── UserRepository.java
├── service/
│ ├── UserService.java
│ └── impl/
│ └── UserServiceImpl.java
├── config/
│ └── OpenApiConfig.java
└── UserManagementApplication.java
The API returns appropriate HTTP status codes and error messages:
- 400 Bad Request: Invalid input data
- 404 Not Found: Resource not found
- 409 Conflict: User with the same email already exists
- 500 Internal Server Error: Unexpected server error
./mvnw clean package./mvnw testThis project is licensed under the MIT License - see the LICENSE file for details.