Skip to content

chakricodesjava/springboot-microservice

Repository files navigation

Spring Boot Microservices - Cloud Config

This repository contains three Spring Boot microservices demonstrating Spring Cloud Config architecture:

  1. Config Server - Centralized configuration management server
  2. Config Client - Client application that retrieves configuration from the server
  3. Config Client 2 - Second demo client application with independent configuration

Architecture

architecture-diagram_4k.svg

Prerequisites

  • Java 21 or higher
  • Maven 3.9.11
  • SDKMAN (configured in .sdkmanrc)

Quick Start

Option 1: Using Startup Scripts (Recommended)

Start individual services:

# Terminal 1 - Start Config Server
./start-config-server.sh

# Terminal 2 - Start Config Client
./start-config-client.sh

# Terminal 3 - Start Config Client 2 (Optional)
./start-config-client-2.sh

Start all services at once:

./start-all-services.sh

This will open separate terminal windows for each service (macOS only).

Run with specific profile:

./run-with-profile.sh

Interactive script to choose service and profile (default/dev/prod).

Stop all running services:

./stop-all-services.sh

Option 2: Manual Maven Commands

1. Start Config Server

cd config-server
mvn clean install -DskipTests
mvn spring-boot:run

The Config Server will start on http://localhost:8888

2. Start Config Client

In a new terminal:

cd config-client
mvn clean install -DskipTests
mvn spring-boot:run

The Config Client will start on http://localhost:8080

3. Start Config Client 2 (Optional Demo)

In another terminal:

cd config-client-2
mvn clean install -DskipTests
mvn spring-boot:run

The Config Client 2 will start on http://localhost:8081

Option 3: Build All Modules at Once

# Build all modules from root
mvn clean install -DskipTests

# Run specific module
mvn spring-boot:run -pl config-server
mvn spring-boot:run -pl config-client
mvn spring-boot:run -pl config-client-2

Testing

Once both applications are running:

# Test Config Client
curl http://localhost:8080/api/message
curl http://localhost:8080/api/config

# Test Config Client 2
curl http://localhost:8081/api/message
curl http://localhost:8081/api/config

# Test Config Server directly
curl http://localhost:8888/config-client/default
curl http://localhost:8888/config-client/dev
curl http://localhost:8888/config-client/prod

curl http://localhost:8888/config-client-2/default
curl http://localhost:8888/config-client-2/dev
curl http://localhost:8888/config-client-2/prod

Running with Different Profiles

Using Startup Scripts

./run-with-profile.sh
# Then select service and profile from the menu

Manual Commands

cd config-client
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev

# For Config Client 2
cd config-client-2
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev

Production Profile

cd config-client
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=prod

# For Config Client 2
cd config-client-2
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=prod

Configuration Refresh

Update configuration on the Config Server, then refresh the client:

# Refresh Config Client
curl -X POST http://localhost:8080/actuator/refresh

# Refresh Config Client 2
curl -X POST http://localhost:8081/actuator/refresh

Project Structure

springboot-microservice/
├── config-server/              # Spring Cloud Config Server
│   ├── src/
│   │   ├── main/
│   │   │   ├── java/
│   │   │   └── resources/
│   │   │       ├── application.yml
│   │   │       └── config/
│   │   │           ├── config-client.yml
│   │   │           ├── config-client-dev.yml
│   │   │           ├── config-client-prod.yml
│   │   │           ├── config-client-2.yml
│   │   │           ├── config-client-2-dev.yml
│   │   │           └── config-client-2-prod.yml
│   │   └── test/
│   └── pom.xml
│
├── config-client/              # Spring Cloud Config Client
│   ├── src/
│   │   ├── main/
│   │   │   ├── java/
│   │   │   └── resources/
│   │   │       ├── application.yml
│   │   │       └── bootstrap.yml
│   │   └── test/
│   └── pom.xml
│
├── config-client-2/            # Spring Cloud Config Client 2 (Demo)
│   ├── src/
│   │   ├── main/
│   │   │   ├── java/
│   │   │   └── resources/
│   │   │       ├── application.yml
│   │   │       └── bootstrap.yml
│   │   └── test/
│   └── pom.xml
│
├── start-config-server.sh
├── start-config-client.sh
├── start-config-client-2.sh
├── start-all-services.sh
├── run-with-profile.sh
├── stop-all-services.sh
└── README.md

Features

Config Server

  • Centralized configuration management
  • Support for multiple environments (default, dev, prod)
  • Git backend support (https://github.com/chakricodesjava/config-repo)
  • Native file system backend (can be toggled)
  • REST API for configuration retrieval
  • Serves configuration for multiple client applications

Config Client

  • Dynamic configuration loading from Config Server
  • Profile-based configuration
  • Runtime configuration refresh
  • RESTful endpoints to view current configuration
  • Runs on port 8080

Config Client 2

  • Independent demo client application
  • Same capabilities as Config Client
  • Separate configuration files
  • Runs on port 8081

Technologies Used

  • Spring Boot 3.3.4
  • Spring Cloud Config 2023.0.3
  • Java 21
  • Maven 3.9.11

Additional Resources

Available Scripts

Script Description
start-config-server.sh Start Config Server with helpful output
start-config-client.sh Start Config Client with API endpoint info
start-config-client-2.sh Start Config Client 2 with API endpoint info
start-all-services.sh Start all services in separate terminals
run-with-profile.sh Interactive script to run any service with any profile
stop-all-services.sh Stop all running Spring Boot services

Script Features

All startup scripts include:

  • ✅ Automated build with mvn clean install -DskipTests
  • ✅ Error handling and validation
  • ✅ Helpful status messages with emojis
  • ✅ API endpoint information
  • ✅ Port and URL details
  • ✅ Press Ctrl+C instructions

About

springboot-microservice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •