|
1 | 1 | # spring_boot_java_random_user |
| 2 | + |
| 3 | +Spring Boot Java project that exposes a REST API consuming the public [Random User](https://randomuser.me/) API. |
| 4 | +The interactive API documentation is available via **Swagger UI / OpenAPI**. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 🛠️ Tech Stack |
| 9 | + |
| 10 | +| Technology | Version | |
| 11 | +|----------------------|-----------------| |
| 12 | +| Java | 25 | |
| 13 | +| Spring Boot | 4.0.3 | |
| 14 | +| Spring Web MVC | (managed by Boot) | |
| 15 | +| Spring Actuator | (managed by Boot) | |
| 16 | +| springdoc-openapi | 3.0.1 | |
| 17 | +| PostgreSQL (driver) | (managed by Boot) | |
| 18 | +| Testcontainers | (managed by Boot) | |
| 19 | +| Maven | Wrapper included | |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## 📋 Prerequisites |
| 24 | + |
| 25 | +- **Java 25** (or compatible version) |
| 26 | +- **Maven** (or use the included `./mvnw` wrapper) |
| 27 | +- **PostgreSQL** running (if data persistence is enabled) |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## ⚙️ Configuration |
| 32 | + |
| 33 | +The main configuration file is located at: |
| 34 | + |
| 35 | +``` |
| 36 | +src/main/resources/application.properties |
| 37 | +``` |
| 38 | + |
| 39 | +### Properties to configure |
| 40 | + |
| 41 | +```properties |
| 42 | +spring.application.name=spring_boot_java_random_user |
| 43 | + |
| 44 | +# Swagger UI — available at /api |
| 45 | +springdoc.swagger-ui.path=/api |
| 46 | + |
| 47 | +# PostgreSQL datasource (add these if you use persistence) |
| 48 | +spring.datasource.url=jdbc:postgresql://localhost:5432/<database_name> |
| 49 | +spring.datasource.username=<username> |
| 50 | +spring.datasource.password=<password> |
| 51 | +spring.datasource.driver-class-name=org.postgresql.Driver |
| 52 | +``` |
| 53 | + |
| 54 | +> ⚠️ **Common startup error**: |
| 55 | +> ``` |
| 56 | +> Failed to configure a DataSource: 'url' attribute is not specified |
| 57 | +> and no embedded datasource could be configured. |
| 58 | +> Reason: Failed to determine a suitable driver class |
| 59 | +> ``` |
| 60 | +> This error occurs because the PostgreSQL driver is present in the dependencies but the datasource URL is not configured. |
| 61 | +> **Fix**: either add the `spring.datasource.*` properties above, or exclude the DataSource auto-configuration if no database is needed: |
| 62 | +> ```properties |
| 63 | +> spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration |
| 64 | +> ``` |
| 65 | +
|
| 66 | +--- |
| 67 | +
|
| 68 | +## 🚀 Running the project |
| 69 | +
|
| 70 | +### With the Maven Wrapper (recommended) |
| 71 | +
|
| 72 | +```bash |
| 73 | +./mvnw spring-boot:run |
| 74 | +``` |
| 75 | +
|
| 76 | +### With Maven installed |
| 77 | + |
| 78 | +```bash |
| 79 | +mvn spring-boot:run |
| 80 | +``` |
| 81 | + |
| 82 | +### Build and run the JAR |
| 83 | + |
| 84 | +```bash |
| 85 | +./mvnw clean package |
| 86 | +java -jar target/spring_boot_java_random_user-0.0.1-SNAPSHOT.jar |
| 87 | +``` |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## 📖 API Documentation (Swagger UI) |
| 92 | + |
| 93 | +Once the project is running, the interactive documentation is available at: |
| 94 | + |
| 95 | +``` |
| 96 | +http://localhost:8080/api |
| 97 | +``` |
| 98 | + |
| 99 | +The raw OpenAPI specification (JSON) is available at: |
| 100 | + |
| 101 | +``` |
| 102 | +http://localhost:8080/v3/api-docs |
| 103 | +``` |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## 🔍 Monitoring (Actuator) |
| 108 | + |
| 109 | +Spring Boot Actuator is enabled. Health endpoints are available at: |
| 110 | + |
| 111 | +``` |
| 112 | +http://localhost:8080/actuator |
| 113 | +http://localhost:8080/actuator/health |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 🧪 Tests |
| 119 | + |
| 120 | +Run unit and integration tests: |
| 121 | + |
| 122 | +```bash |
| 123 | +./mvnw test |
| 124 | +``` |
| 125 | + |
| 126 | +Tests use **Testcontainers** to spin up ephemeral Docker containers for external dependencies (e.g. PostgreSQL). |
| 127 | + |
| 128 | +> **Prerequisite for tests**: Docker must be installed and running. |
| 129 | +
|
| 130 | +--- |
| 131 | + |
| 132 | +## 📁 Project structure |
| 133 | + |
| 134 | +``` |
| 135 | +src/ |
| 136 | +├── main/ |
| 137 | +│ ├── java/com/xpeho/spring_boot_java_random_user/ |
| 138 | +│ │ └── SpringBootJavaRandomUserApplication.java # Entry point |
| 139 | +│ └── resources/ |
| 140 | +│ └── application.properties # Configuration |
| 141 | +└── test/ |
| 142 | + └── java/com/xpeho/spring_boot_java_random_user/ |
| 143 | + └── SpringBootJavaRandomUserApplicationTests.java |
| 144 | +``` |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +## 🌐 External API |
| 149 | + |
| 150 | +This project consumes the public **Random User Generator** API: |
| 151 | + |
| 152 | +- **URL**: [https://randomuser.me/api/](https://randomuser.me/api/) |
| 153 | +- **Documentation**: [https://randomuser.me/documentation](https://randomuser.me/documentation) |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## ✅ Todo |
| 158 | + |
| 159 | +- [ ] [Add Sonarqube in the project](https://github.com/XPEHO/spring_boot_java_random_user/issues/2) |
| 160 | +- [ ] [Add PostgreSQL database with docker](https://github.com/XPEHO/spring_boot_java_random_user/issues/6) |
| 161 | +- [ ] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5) |
| 162 | +- [ ] [Add this endpoint get /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/8) |
| 163 | +- [ ] [Add this endpoint put /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9) |
| 164 | +- [ ] [Add this endpoint delete /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/10) |
| 165 | +- [ ] [Add this endpoint post /user](https://github.com/XPEHO/spring_boot_java_random_user/issues/11) |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +## 👤 Author |
| 170 | + |
| 171 | +Project developed by **XPEHO**. |
0 commit comments