A complete microservices architecture project using Spring Boot 3.2.0, Spring Cloud 2023.0.0, and Java 17.
microservices-tp/
├── discovery-server/ # Eureka Discovery Server (Port 8761)
├── gateway/ # Spring Cloud Gateway (Port 8080)
├── user-service/ # User Microservice (Port 8084)
├── product-service/ # Product Microservice (Port 8083)
└── pom.xml # Parent POM
- Eureka Discovery Server: Service registry for all microservices
- Spring Cloud Gateway: API Gateway with load balancing
- User Service: REST API for user management
- Product Service: REST API for product management
- Java 17 or higher
- Maven 3.6 or higher
- IDE (IntelliJ IDEA recommended)
From the root directory, run:
mvn clean installcd discovery-server
mvn spring-boot:runWait until Eureka is fully started, then access: http://localhost:8761
Open a new terminal:
cd user-service
mvn spring-boot:runService will register with Eureka on port 8084
Open a new terminal:
cd product-service
mvn spring-boot:runService will register with Eureka on port 8083
Open a new terminal:
cd gateway
mvn spring-boot:runGateway will start on port 8080
-
Check Eureka Dashboard: http://localhost:8761
- You should see
user-service,product-service, andgatewayregistered
- You should see
-
Test Direct Access:
- User Service: http://localhost:8084/users
- Product Service: http://localhost:8083/produits
-
Test via Gateway (Recommended):
- Users: http://localhost:8080/users
- Products: http://localhost:8080/produits
- Specific User: http://localhost:8080/users/1
Via Gateway (http://localhost:8080)
GET /users- Get all users[ {"id": "1", "name": "Oussama", "email": "oussama@example.com"}, {"id": "2", "name": "Yuno", "email": "yuno@example.com"} ]GET /users/{id}- Get user by ID{"id": "1", "name": "User-1", "email": "user1@example.com"}
GET /produits- Get all products[ {"id": "p1", "name": "Laptop", "price": "999.99"}, {"id": "p2", "name": "Phone", "price": "599.99"} ]
-
Import Project:
- File → Open → Select
microservices-tpfolder - IntelliJ will detect it as a Maven project
- File → Open → Select
-
Run Configurations:
- Create 4 separate Spring Boot run configurations:
DiscoveryServerApplicationUserServiceApplicationProductServiceApplicationGatewayApplication
- Create 4 separate Spring Boot run configurations:
-
Start Services:
- Run them in order: Discovery → User → Product → Gateway
- Spring Boot 3.2.0
- Spring Cloud 2023.0.0
- Spring Cloud Netflix Eureka: Service Discovery
- Spring Cloud Gateway: API Gateway with Load Balancing
- Java 17
- Maven: Build Tool
| Service | Port |
|---|---|
| Discovery Server | 8761 |
| Gateway | 8080 |
| Product Service | 8083 |
| User Service | 8084 |
✅ Service Discovery with Eureka
✅ Load Balancing via Spring Cloud Gateway
✅ RESTful APIs
✅ Multi-module Maven project
✅ Production-ready configuration
- Always start the Discovery Server (Eureka) first
- Wait for each service to fully register before starting the next one
- Check the Eureka dashboard to verify all services are registered
- Use the Gateway (port 8080) for accessing services in production scenarios
Services not registering with Eureka:
- Ensure Discovery Server is running first
- Check
application.ymlfor correct Eureka URL - Wait 30-60 seconds for registration to complete
Gateway not routing:
- Verify all services are registered in Eureka dashboard
- Check Gateway logs for routing configuration
- Ensure service names match in Eureka and Gateway routes
Port conflicts:
- Make sure no other applications are using ports 8080, 8083, 8084, or 8761
- You can change ports in respective
application.ymlfiles
Essalmani Oussama
Microservices TP Project - Spring Boot 3 & Spring Cloud