Spring Microservices in Action Chapter05 프로젝트
💪 Spring Microservices in Action Chapter05 프로젝트 분석
🔮 프로젝트 개요
Spring Microservices in Action 2nd Edition Chapter05 프로젝트는 Spring Cloud Config Server를 기반으로 배포가 가능한 두 개의 모듈을 합법한 모듈 관리 구조로 구성되어 있습니다. 각 메인 메서드 명령을 이용하여 모듈을 만들고 배포할 수 있습니다.
⚡️ 프로젝트 요약
- Config Server: Spring Cloud Config Server 기반 서버 서비스
- Licensing Service: 소프트웨어 라이선스 개발 서비스
- Docker 배포: 하나의 docker-compose.yml 파일을 이용하여 모듈을 배포 가능
- Database: PostgreSQL을 기반으로 회사 조직 및 소프트웨어 라이센싱 데이터를 관리
- Spring Boot 3.4.3: Spring Boot의 버전 3.4.3을 기반으로 최신 스프링 부트 버전을 적용한 구조
🗂️ 파일 구성
📦 chapter05
├── 📂 configserver # Spring Cloud Config Server 프로젝트
│ ├── 📂 src
│ │ ├── 📂 main
│ │ │ ├── 📂 java/com/optimagrowth/configserver
│ │ │ │ ├── ConfigServerApplication.java # Config Server 메인 클래스
│ │ │ ├── 📂 resources
| | | | |── 📂config
│ │ │ │ ├── application.yml # Config Server 설정 파일(미사용)
│ │ │ │ ├── bootstrap.yml # Spring Cloud Config를 위한 설정
│ │ ├── 📂 test
│ ├── pom.xml # Maven 프로젝트 파일
│ ├── Dockerfile # Docker 이미지 빌드 파일
│ ├── README.md # 프로젝트 설명 파일
│
├── 📂 licensing-service # 라이선스 관리 서비스 (Licensing Service)
│ ├── 📂 src
│ │ ├── 📂 main
│ │ │ ├── 📂 java/com/optimagrowth/license
│ │ │ │ ├── LicenseServiceApplication.java # Licensing Service 메인 클래스
│ │ │ │ ├── controller/ # REST 컨트롤러
│ │ │ │ ├── model/ # 엔티티 및 DTO
│ │ │ │ ├── repository/ # JPA Repository
│ │ │ │ ├── service/ # 비즈니스 로직
│ │ │ │ ├── config/ # Spring Cloud Config 설정
│ │ │ ├── 📂 resources
│ │ │ │ ├── application.yml # Licensing Service 설정(미사용)
│ │ │ │ ├── bootstrap.yml # Config Server와 연결 설정
│ │ ├── 📂 test
│ ├── pom.xml # Maven 프로젝트 파일
│ ├── Dockerfile # Docker 이미지 빌드 파일
│ ├── README.md # 프로젝트 설명 파일
│
├── 📂 docker # Docker compose 관련 설정
| ├── 📂vault
| | ├── 📂config # vault의 raft를 사용하지 않음(하위 파일들 미사용)
| | ├── 📂file
| | | ├── application.json
| | | ├── application_dev.json
| | | ├── default.json
| | | ├── dev.json
| | | ├── prod.json
| | ├── vault-init.sh
│ ├── docker-compose.yml # Docker Compose 설정
│ ├── data.sql # PostgreSQL 초기화 스크립트
│ |── init.sql
|
├── pom.xml # 전체 프로젝트 Maven 파일
├── build-for-m1.sh # mac os를 위한 빌드 스크립트 파일
└── README.md # 프로젝트 전체 설명 파일
🔧 Parent POM (모듈 공통 설정) 분석
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.optimagrowth</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>ostock-parent-pom</artifactId>
<packaging>pom</packaging>
<name>optimagrowth-parent-pom</name>
<description>Parent Pom for the optimagrowth project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<docker.image.prefix>ostock</docker.image.prefix>
</properties>
<modules>
<module>configserver</module>
<module>licensing-service</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Chapter05 Project POM 파일은 여러 마이크로서비스 프로젝트(configserver, licensing-service)를 관리하는 부모 POM(Parent POM) 역할을 합니다.
✅ 주요 기능
- 멀티 마이크로서비스 관리 (configserver, licensing-service)
- Spring Boot Parent POM 상속
- Docker 이미지 빌드 플러그인 설정(비활성화)
- 공통 속성(Docker 이미지 Prefix) 관리
🏗 pom.xml 주요 내용 분석
1️⃣ 프로젝트 메타데이터
<groupId>com.optimagrowth</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>ostock-parent-pom</artifactId>
<packaging>pom</packaging>
<name>optimagrowth-parent-pom</name>
<description>Parent Pom for the optimagrowth project</description>
- groupId: com.optimagrowth
- artifactId: ostock-parent-pom
- version: 0.0.1-SNAPSHOT (개발 단계)
- packaging: pom (빌드 시 패키징되지 않고 다른 모듈을 관리하는 부모 역할)
- name / description: 프로젝트 설명
💡 이 POM 파일은 빌드 가능한 애플리케이션이 아니라,
📌 다른 모듈(configserver, licensing-service)을 관리하는 부모 역할을 합니다.
2️⃣ Spring Boot Parent POM 상속
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
- Spring Boot의 디폴트 설정을 상속 (spring-boot-starter-parent)
- 버전: Spring Boot 3.4.3
- relativePath 설정을 비워 로컬이 아닌 중앙 리포지토리에서 부모 POM을 찾도록 설정
💡 Spring Boot Starter Parent를 상속하면 다음과 같은 이점이 있습니다.
✅ 공통적인 Spring Boot 의존성을 자동 관리
✅ 기본적인 Maven 플러그인 및 빌드 설정 제공
3️⃣ 공통 속성(properties) 설정
<properties>
<docker.image.prefix>ostock</docker.image.prefix>
</properties>
- docker.image.prefix: Docker 이미지 빌드시 사용할 접두어(prefix) 설정
- 예: ostock/configserver, ostock/licensing-service 등의 이미지 태그로 빌드 가능
📌 각 서브 모듈(configserver, licensing-service)이 Docker 빌드를 할 때 이 값을 사용할 수 있음
4️⃣ 멀티 모듈 설정
<modules>
<module>configserver</module>
<module>licensing-service</module>
</modules>
✅ 이 프로젝트는 멀티 모듈 구조이며, configserver와 licensing-service 모듈을 포함합니다.
- configserver: Spring Cloud Config Server
- licensing-service: 마이크로서비스 예제
📌 이 설정 덕분에 mvn clean package(또는 install)을 실행하면 두 개의 모듈이 한꺼번에 빌드됩니다. 🚀
5️⃣ 빌드 플러그인 설정
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
✅ Docker 빌드 플러그인 설정(비활성화)
- com.spotify:dockerfile-maven-plugin:
- Docker 이미지를 빌드할 때 사용하는 플러그인
- 현재 skip=true로 설정되어 parent 프로젝트에서는 무시되고, 특정 모듈에서만 Docker 빌드를 수행할 경우
- 서브 모듈에서 개별적으로 활성화할 수 있음
📌 Docker 빌드를 비활성화한 이유?
- ostock-parent-pom 자체는 실행 가능한 애플리케이션이 아님
- 개별 모듈에서 Docker 빌드를 실행하도록 설정
- 필요할 때만 Docker 이미지 빌드를 실행하기 위함
📝 Chapter05 pom.xml의 특징
✔ Spring Boot Parent POM을 상속
✔ 멀티 모듈(configserver, licensing-service)을 관리
✔ 공통 속성(Docker 이미지 프리픽스) 설정
✔ Docker 빌드 플러그인 포함 (비활성화 상태)
🚀 전체 프로젝트 실행방법
1️⃣ 전체 모듈 빌드
mvn clean install dockerfile:build
2️⃣ docker compose 실행
docker-compose -f docker/docker-compose.yml up
💡 chapter05의 pom.xml은 Spring Microservices 프로젝트의 Parent POM으로,
✅ 각 마이크로서비스 모듈을 관리하고,
✅ 공통 설정을 정의하며,
✅ 개별 모듈에서 Docker 빌드 및 실행을 수행할 수 있도록 설계되었습니다.
📌 멀티 모듈 프로젝트를 관리할 때 Parent POM을 활용하면, 코드 중복을 줄이고 유지보수를 쉽게 할 수 있습니다.
출처 : https://github.com/ihuaylupo/manning-smia/tree/master/chapter5
manning-smia/chapter5 at master · ihuaylupo/manning-smia
Spring Microservices in Action - Second Edition - Code Examples - ihuaylupo/manning-smia
github.com
※ Spring Microservices in Action 2nd Edition chapter05를 일부 수정함