A comprehensive Spring Boot 4.0.2 demo application showcasing modern enterprise Java development practices with REST APIs, JPA/Hibernate, and various Spring Boot features.
- Overview
- Technologies
- Features
- Prerequisites
- Getting Started
- Project Structure
- API Endpoints
- Configuration
- Development
- Testing
- Building
- Documentation
This is a demo Spring Boot application that demonstrates:
- RESTful API development
- JPA/Hibernate for database operations
- Employee and Department management system
- Spring AOP for cross-cutting concerns
- API documentation with SpringDoc OpenAPI
- Health monitoring with Spring Boot Actuator
- JSON logging with Logstash encoder
- Java: 25
- Spring Boot: 4.0.2
- Database: H2 (in-memory) / MySQL
- Build Tool: Maven
- ORM: Hibernate/JPA
- API Documentation: SpringDoc OpenAPI 2.6.0
- Mapping: ModelMapper 3.2.0
- Logging: Logback with Logstash encoder 4.9
- Monitoring: Spring Boot Actuator
- Code Generation: Lombok
- Employee Management: CRUD operations for employees
- Department Management: Department tracking and relationships
- RESTful APIs: Clean, resource-oriented endpoints
- Data Validation: Jakarta Bean Validation
- Exception Handling: Global exception handler
- DTO Pattern: Entity-DTO mapping for clean API contracts
- Spring AOP: Aspect-oriented programming support
- JPA Auditing: Automatic tracking of entity changes
- H2 Console: In-memory database management interface
- Health Checks: Spring Boot Actuator health endpoints
- OpenAPI/Swagger: Interactive API documentation
- JSON Logging: Structured logging for analysis
- Java 25 or higher
- Maven 3.6+ (or use the Nx wrapper)
- H2 Database (embedded) or MySQL (optional)
cd c:/software-dev/gx.java/apps/springbootupUsing Nx (recommended):
nx run springbootup:buildOr using npm/pnpm:
pnpm run springbootup:buildOr using Maven directly:
mvn clean packageUsing Maven:
mvn spring-boot:runOr run the built JAR:
java -jar target/demo-0.0.1-SNAPSHOT.jarThe application will start on http://localhost:8080
src/
βββ main/
β βββ java/com/example/demo/
β β βββ aspect/ # AOP aspects
β β βββ common/ # Common utilities, mappers, exception handlers
β β βββ config/ # Configuration classes
β β β βββ AopConfig.java
β β β βββ DatabaseConfig.java
β β β βββ ModelMapperConfig.java
β β β βββ OpenAPIConfig.java
β β βββ controllers/ # REST controllers
β β β βββ EmployeeController.java
β β βββ dao/ # Data Access Objects
β β βββ dto/ # Data Transfer Objects
β β β βββ EmployeeDto.java
β β β βββ DepartmentDto.java
β β βββ entity/ # JPA entities
β β β βββ Employee.java
β β β βββ Department.java
β β βββ health/ # Custom health indicators
β β βββ repositories/ # Spring Data JPA repositories
β β β βββ EmployeeRepository.java
β β β βββ DepartmentRepository.java
β β βββ services/ # Business logic services
β β β βββ employee/
β β β βββ department/
β β β βββ trafficfortune/
β β βββ SpringbootupApplication.java
β βββ resources/
β βββ application.properties # Application configuration
β βββ data.sql # Initial data
β βββ schema.sql # Database schema
βββ test/ # Test classes
| Method | Endpoint | Description |
|---|---|---|
| GET | /employees/list |
Get all employees |
| GET | /employees/get/{id} |
Get employee by ID |
| POST | /employees/save |
Create or update employee |
| GET | /employees/delete/{id} |
Delete employee |
| Method | Endpoint | Description |
|---|---|---|
| GET | /actuator/health |
Application health status |
- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI JSON:
http://localhost:8080/v3/api-docs
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.h2.console.enabled=trueAccess H2 Console at: http://localhost:8080/h2-console
Update application.properties with MySQL connection details:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database
spring.datasource.username=your_username
spring.datasource.password=your_passwordKey configurations in application.properties:
- Port: Default is 8080
- JPA: Hibernate DDL auto-update enabled
- Actuator: Health endpoint exposed
- Logging: DEBUG level for root, INFO for Spring
- H2 Console: Enabled for development
The application uses Spring Boot DevTools (when available) for:
- Automatic restarts
- LiveReload support
- Enhanced development experience
The project uses:
- Lombok: Reduce boilerplate code with annotations
- Builder Pattern: For entity construction
- DTO Pattern: Separate API contracts from domain models
- Create entity in
entity/package - Create corresponding DTO in
dto/package - Create repository extending
JpaRepository - Implement service in
services/package - Create REST controller in
controllers/package - Add tests in
src/test/
Run tests using:
# Using Nx
nx run springbootup:test
# Using Maven
mvn testnx run springbootup:buildmvn clean package -DskipTestsThe JAR file will be created in target/demo-0.0.1-SNAPSHOT.jar
Once the application is running, visit:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI Spec: http://localhost:8080/v3/api-docs
The OpenAPI documentation is auto-generated and includes:
- All REST endpoints
- Request/response schemas
- Try-it-out functionality
- Model definitions
Monitor application health:
This is a demo application. For production use, consider:
- Adding Spring Security
- Implementing authentication/authorization
- Securing actuator endpoints
- Using environment-specific configurations
- Enabling HTTPS
- Implementing rate limiting
This is a demo project for educational purposes.
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
For issues or questions, please refer to the main project documentation or create an issue in the repository.
Version: 0.0.1-SNAPSHOT
Artifact ID: demo
Group ID: com.springboot.collection