⬇ 멀티 모듈을 적용하기 전의 패키지 구조
(기존에는 서비스의 모든 코드들이 단일 모듈에 포함된 상태)
멀티 모듈은 하나의 시스템이나 프로젝트를 여러 개의 독립적인 모듈로 분리하여 구성하는 방식입니다. 모듈화된 구조는 코드의 재사용성을 높여주는데, 비슷한 기능을 가진 모듈을 다른 프로젝트에서도 재사용해서 개발 시간과 노력을 절약할 수 있다는 장점이 있습니다.
이렇게 구성을 한 덕분에, 공통된 부분에서 수정사항이 발생해도 분리한 모듈에서 한 번만 수정을 하면 되기 때문에 유지 보수 측면에서 더 간편해졌습니다.
모듈을 생성하고나면 settings.gradle에 자동으로 include된다고하던데
자동으로 뜨는거는 모르겠고,, 난 직접 입력해줬음
물론 실행에 문제 없이 잘 돌아감!
💡 subprojects 에는 setting.gradle 에 include 된 모든 프로젝트에 공통적으로 적용할 설정작성
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}
// 하위 모든 프로젝트 공통 세팅
subprojects {
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
apply plugin: "java"
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = "11"
repositories {
mavenCentral()
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
java {
sourceCompatibility = '21'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// DB
runtimeOnly 'com.mysql:mysql-connector-j'
// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// Email 인증
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'javax.mail:mail:1.4.7'
// Spring Context Support
implementation 'org.springframework:spring-context-support:5.3.9'
//redis 추가
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.6.3'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// spring security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2', 'io.jsonwebtoken:jjwt-jackson:0.11.2'
// Jasypt
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
// QueryDSL - 스프링 부트 3.0 이상
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
implementation "com.querydsl:querydsl-core"
implementation "com.querydsl:querydsl-collections"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
// java.lang.NoClassDefFoundError (javax.annotation.Generated) 에러 대응 코드
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
// java.lang.NoClassDefFoundError (javax.annotation.Entity) 에러 대응 코드
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.junit.vintage", module: "junit-vintage-engine"
}
}
tasks.named('test') {
useJUnitPlatform()
}
}
// order-service 설정
project(':order-service') {
bootJar { enabled = false }
jar { enabled = true }
}
// product-service 설정
project(':product-service') {
bootJar { enabled = false }
jar { enabled = true }
}
// user-service 설정
project(':user-service') {
bootJar { enabled = false }
jar { enabled = true }
}
- bootJar { enabled = false } : Spring Boot는 기본적으로 bootJar 태스크를 사용하여 실행 가능한 JAR 파일을 생성합니다. 이 옵션을 false 로 설정하면, 빌드 프로세스 중에 실행 가능한 JAR 파일이 생성되지 않습니다.
- jar { enabled = true } : 일반적인 Java 프로젝트에서 생성되는 JAR 파일을 활성화하는 설정입니다. 이 옵션을 true 로 설정하면, 빌드 프로세스 중에 일반적인 JAR 파일이 생성됩니다. 일반적으로 이 JAR 파일은 프로젝트의 컴파일된 클래스 파일 및 리소스 파일을 포함합니다.
정상적으로 실행되는지 확인해보기 ( ✔멀티모듈 한번에 실행시키는 방법 )
처음에는 data init을 위해 설정해둔 파일 data.sql 이 있어 초기화시 문제가 발생했다.
테이블 별로 분리해서 넣어주니 제대로 실행되는것을 볼 수 있었음
맵핑해둔 페이지가 없어서 화이트라벨 페이지도 잘 나온다
아직 서로 연관관계가 없어서
product 도메인을 불러오지 못하고있는모습
이제 db 분리..? 뭐랑..
openFeign 어쩌구 찾아보구 그거하러갈예정