From 12767a38326b37c86ea1e2d0b9f8266c0e3adc06 Mon Sep 17 00:00:00 2001 From: coco3x Date: Thu, 19 Dec 2024 16:09:13 +0900 Subject: [PATCH 01/22] =?UTF-8?q?update:=20NetworkConfig=20-=20@Value=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whoz_in/log_writer/config/NetworkConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/NetworkConfig.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/NetworkConfig.java index ff8e5a60..020f6217 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/NetworkConfig.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/NetworkConfig.java @@ -15,7 +15,7 @@ //실행시킬 프로세스들이 필요로 하는 정보를 제공하는 역할을 한다. //이를 위해 network-.json에서 설정값을 가져온다. -//설정된 값들이 +//local 혹은 prod만 지원한다. @Getter @Component public class NetworkConfig { @@ -25,7 +25,7 @@ public class NetworkConfig { private final List arpList; @SuppressWarnings("unchecked") - public NetworkConfig(@Value("${spring.profiles.active:default}") String profile, ResourceLoader loader, ObjectMapper mapper) { + public NetworkConfig(@Value("${spring.profiles.active}") String profile, ResourceLoader loader, ObjectMapper mapper) { String jsonPath = "classpath:/network-%s.json".formatted(profile); Resource resource = loader.getResource(jsonPath); Map map; From f9bffbc7e81491795b39f8a6fcdbaeb6c9020ead Mon Sep 17 00:00:00 2001 From: coco3x Date: Thu, 19 Dec 2024 16:32:03 +0900 Subject: [PATCH 02/22] =?UTF-8?q?update(main-api):=20domain=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20compileOnly=20->=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/main-api/build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/main-api/build.gradle b/modules/main-api/build.gradle index 27ea1014..40a62545 100644 --- a/modules/main-api/build.gradle +++ b/modules/main-api/build.gradle @@ -14,16 +14,15 @@ repositories { } dependencies { - compileOnly project(':modules:domain') + implementation project(':modules:domain') - //for domain DI (runtimeOnly) + //domain 구현 모듈 runtimeOnly project(":modules:infrastructure:domain-jpa") - //for api DI (runtimeOnly - 순환 의존 방지) + //main-api 구현 모듈 (runtimeOnly - 순환 의존 방지) runtimeOnly project(":modules:infrastructure:spring") runtimeOnly project(":modules:infrastructure:api-query-jpa") - //직접 의존 implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' // implementation 'org.springframework.boot:spring-boot-starter-security' From f4be8ec4c08ae0a6dcad5150f28a2821b32f3b01 Mon Sep 17 00:00:00 2001 From: coco3x Date: Fri, 20 Dec 2024 14:19:27 +0900 Subject: [PATCH 03/22] rename: NetworkLog -> NetworkApi --- .../NetworkApiApplication.java} | 6 +++--- .../common/util/HttpUtils.java | 2 +- .../common/util/IpHolder.java | 2 +- .../common/util/RequesterInfo.java | 2 +- .../config/WebMvcConfig.java | 4 ++-- .../config/interceptor/ClientIpInterceptor.java | 4 ++-- .../controller/IpAddressController.java | 5 ++--- modules/network-api/src/main/resources/application.yml | 10 ++++------ 8 files changed, 16 insertions(+), 19 deletions(-) rename modules/network-api/src/main/java/com/whoz_in/{network_log/NetworkLogApplication.java => network_api/NetworkApiApplication.java} (63%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/common/util/HttpUtils.java (80%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/common/util/IpHolder.java (88%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/common/util/RequesterInfo.java (70%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/config/WebMvcConfig.java (90%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/config/interceptor/ClientIpInterceptor.java (90%) rename modules/network-api/src/main/java/com/whoz_in/{network_log => network_api}/controller/IpAddressController.java (82%) diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/NetworkLogApplication.java b/modules/network-api/src/main/java/com/whoz_in/network_api/NetworkApiApplication.java similarity index 63% rename from modules/network-api/src/main/java/com/whoz_in/network_log/NetworkLogApplication.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/NetworkApiApplication.java index 145b6f17..61107558 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/NetworkLogApplication.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/NetworkApiApplication.java @@ -1,13 +1,13 @@ -package com.whoz_in.network_log; +package com.whoz_in.network_api; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = {"com.whoz_in"}) -public class NetworkLogApplication { +public class NetworkApiApplication { public static void main(String[] args) { - SpringApplication.run(NetworkLogApplication.class, args); + SpringApplication.run(NetworkApiApplication.class, args); } } diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/HttpUtils.java b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/HttpUtils.java similarity index 80% rename from modules/network-api/src/main/java/com/whoz_in/network_log/common/util/HttpUtils.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/common/util/HttpUtils.java index cb1193bb..be074c1b 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/HttpUtils.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/HttpUtils.java @@ -1,4 +1,4 @@ -package com.whoz_in.network_log.common.util; +package com.whoz_in.network_api.common.util; import jakarta.servlet.http.HttpServletRequest; diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/IpHolder.java b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/IpHolder.java similarity index 88% rename from modules/network-api/src/main/java/com/whoz_in/network_log/common/util/IpHolder.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/common/util/IpHolder.java index 44283833..c22cd375 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/IpHolder.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/IpHolder.java @@ -1,4 +1,4 @@ -package com.whoz_in.network_log.common.util; +package com.whoz_in.network_api.common.util; import org.springframework.stereotype.Component; diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/RequesterInfo.java b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/RequesterInfo.java similarity index 70% rename from modules/network-api/src/main/java/com/whoz_in/network_log/common/util/RequesterInfo.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/common/util/RequesterInfo.java index f481fa3b..a1bf46ce 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/common/util/RequesterInfo.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/common/util/RequesterInfo.java @@ -1,4 +1,4 @@ -package com.whoz_in.network_log.common.util; +package com.whoz_in.network_api.common.util; public interface RequesterInfo { diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/config/WebMvcConfig.java b/modules/network-api/src/main/java/com/whoz_in/network_api/config/WebMvcConfig.java similarity index 90% rename from modules/network-api/src/main/java/com/whoz_in/network_log/config/WebMvcConfig.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/config/WebMvcConfig.java index 4829162b..a7496f42 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/config/WebMvcConfig.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/config/WebMvcConfig.java @@ -1,6 +1,6 @@ -package com.whoz_in.network_log.config; +package com.whoz_in.network_api.config; -import com.whoz_in.network_log.config.interceptor.ClientIpInterceptor; +import com.whoz_in.network_api.config.interceptor.ClientIpInterceptor; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/config/interceptor/ClientIpInterceptor.java b/modules/network-api/src/main/java/com/whoz_in/network_api/config/interceptor/ClientIpInterceptor.java similarity index 90% rename from modules/network-api/src/main/java/com/whoz_in/network_log/config/interceptor/ClientIpInterceptor.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/config/interceptor/ClientIpInterceptor.java index 67c4b663..9b10a41e 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/config/interceptor/ClientIpInterceptor.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/config/interceptor/ClientIpInterceptor.java @@ -1,6 +1,6 @@ -package com.whoz_in.network_log.config.interceptor; +package com.whoz_in.network_api.config.interceptor; -import com.whoz_in.network_log.common.util.RequesterInfo; +import com.whoz_in.network_api.common.util.RequesterInfo; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; diff --git a/modules/network-api/src/main/java/com/whoz_in/network_log/controller/IpAddressController.java b/modules/network-api/src/main/java/com/whoz_in/network_api/controller/IpAddressController.java similarity index 82% rename from modules/network-api/src/main/java/com/whoz_in/network_log/controller/IpAddressController.java rename to modules/network-api/src/main/java/com/whoz_in/network_api/controller/IpAddressController.java index 31f1461f..a0bd0a58 100644 --- a/modules/network-api/src/main/java/com/whoz_in/network_log/controller/IpAddressController.java +++ b/modules/network-api/src/main/java/com/whoz_in/network_api/controller/IpAddressController.java @@ -1,9 +1,8 @@ -package com.whoz_in.network_log.controller; +package com.whoz_in.network_api.controller; -import com.whoz_in.network_log.common.util.RequesterInfo; +import com.whoz_in.network_api.common.util.RequesterInfo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/modules/network-api/src/main/resources/application.yml b/modules/network-api/src/main/resources/application.yml index 2ed22e3d..fa5fb618 100644 --- a/modules/network-api/src/main/resources/application.yml +++ b/modules/network-api/src/main/resources/application.yml @@ -1,10 +1,4 @@ spring: - application: - name: WhozIn-Network - #@PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 여기서 env를 미리 로드 - config: - import: "classpath:env-network-api.properties" - profiles: group: local: @@ -12,6 +6,10 @@ spring: active: local include: log-writer + #@PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 여기서 env를 미리 로드 + config: + import: "classpath:env-network-api.properties" + logging: discord: webhook-url: ${DISCORD_WEBHOOK_URL} \ No newline at end of file From 42c3edc39688c1d19235f7c3523e470f223e406b Mon Sep 17 00:00:00 2001 From: coco3x Date: Fri, 20 Dec 2024 15:14:51 +0900 Subject: [PATCH 04/22] =?UTF-8?q?chore(domain-jpa):=20yml=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain-jpa/src/main/resources/application-jpa.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml b/modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml index f75b9635..89d151fd 100644 --- a/modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml +++ b/modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml @@ -1,12 +1,9 @@ spring: -# config: -# activate: -# on-profile: local datasource: - url: ${MYSQL_URL} - username: ${MYSQL_USERNAME} - password: ${MYSQL_PASSWORD} - driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + driver-class-name: ${DB_DRIVER_CLASS} jpa: hibernate: ddl-auto: create From 6d05af6a4efc169235e2f27c198542236fbd77d0 Mon Sep 17 00:00:00 2001 From: coco3x Date: Fri, 20 Dec 2024 19:52:17 +0900 Subject: [PATCH 05/22] =?UTF-8?q?feat:=20master-api=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ion-jpa.yml => application-domain-jpa.yml} | 0 .../main/resources/application-main-api.yml | 4 +++ .../src/main/resources/application.yml | 10 ++----- modules/master-api/build.gradle | 29 +++++++++++++++++++ .../master_api/MasterApiApplication.java | 13 +++++++++ .../src/main/resources/application.yml | 7 +++++ .../resources/application-network-api.yml | 11 +++++++ .../src/main/resources/application.yml | 10 +------ settings.gradle | 5 +++- 9 files changed, 72 insertions(+), 17 deletions(-) rename modules/infrastructure/domain-jpa/src/main/resources/{application-jpa.yml => application-domain-jpa.yml} (100%) create mode 100644 modules/main-api/src/main/resources/application-main-api.yml create mode 100644 modules/master-api/build.gradle create mode 100644 modules/master-api/src/main/java/com/whoz_in/master_api/MasterApiApplication.java create mode 100644 modules/master-api/src/main/resources/application.yml create mode 100644 modules/network-api/src/main/resources/application-network-api.yml diff --git a/modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml b/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml similarity index 100% rename from modules/infrastructure/domain-jpa/src/main/resources/application-jpa.yml rename to modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml diff --git a/modules/main-api/src/main/resources/application-main-api.yml b/modules/main-api/src/main/resources/application-main-api.yml new file mode 100644 index 00000000..15415c91 --- /dev/null +++ b/modules/main-api/src/main/resources/application-main-api.yml @@ -0,0 +1,4 @@ +spring: + config: + #domain-jpa 모듈 + import: "classpath:application-domain-jpa.yml" \ No newline at end of file diff --git a/modules/main-api/src/main/resources/application.yml b/modules/main-api/src/main/resources/application.yml index da046977..650d6d19 100644 --- a/modules/main-api/src/main/resources/application.yml +++ b/modules/main-api/src/main/resources/application.yml @@ -1,9 +1,5 @@ +#독립적인 서버로 동작할 때 필요한 yaml spring: profiles: - include: jpa - -management: - endpoints: - web: - exposure: - include: "*" \ No newline at end of file + active: local + include: main-api \ No newline at end of file diff --git a/modules/master-api/build.gradle b/modules/master-api/build.gradle new file mode 100644 index 00000000..c25e100e --- /dev/null +++ b/modules/master-api/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java' + id 'org.springframework.boot' version "3.3.5" + id 'io.spring.dependency-management' version '1.1.5' +} + +group = 'com.whoz_in' +version = '0.0.1-SNAPSHOT' + +jar.enabled = true + +repositories { + mavenCentral() +} + +dependencies { + implementation project(':modules:main-api') + implementation project(':modules:network-api') + + implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' + + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/modules/master-api/src/main/java/com/whoz_in/master_api/MasterApiApplication.java b/modules/master-api/src/main/java/com/whoz_in/master_api/MasterApiApplication.java new file mode 100644 index 00000000..904efd2d --- /dev/null +++ b/modules/master-api/src/main/java/com/whoz_in/master_api/MasterApiApplication.java @@ -0,0 +1,13 @@ +package com.whoz_in.master_api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"com.whoz_in"}) +public class MasterApiApplication { + + public static void main(String[] args) { + SpringApplication.run(MasterApiApplication.class, args); + } + +} \ No newline at end of file diff --git a/modules/master-api/src/main/resources/application.yml b/modules/master-api/src/main/resources/application.yml new file mode 100644 index 00000000..72893cbb --- /dev/null +++ b/modules/master-api/src/main/resources/application.yml @@ -0,0 +1,7 @@ +spring: + profiles: + active: local + config: + import: + - "classpath:application-main-api.yml" + - "classpath:application-network-api.yml" \ No newline at end of file diff --git a/modules/network-api/src/main/resources/application-network-api.yml b/modules/network-api/src/main/resources/application-network-api.yml new file mode 100644 index 00000000..f734875e --- /dev/null +++ b/modules/network-api/src/main/resources/application-network-api.yml @@ -0,0 +1,11 @@ +spring: + config: + import: + #@PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 여기서 env를 미리 로드 + - "classpath:env-network-api.properties" + #log-writer 모듈 + - "classpath:application-log-writer.yml" + +logging: + discord: + webhook-url: ${DISCORD_WEBHOOK_URL} \ No newline at end of file diff --git a/modules/network-api/src/main/resources/application.yml b/modules/network-api/src/main/resources/application.yml index fa5fb618..a32f395f 100644 --- a/modules/network-api/src/main/resources/application.yml +++ b/modules/network-api/src/main/resources/application.yml @@ -4,12 +4,4 @@ spring: local: prod: active: local - include: log-writer - - #@PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 여기서 env를 미리 로드 - config: - import: "classpath:env-network-api.properties" - -logging: - discord: - webhook-url: ${DISCORD_WEBHOOK_URL} \ No newline at end of file + include: network-api \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 47d732a0..f82982df 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,4 +14,7 @@ findProject(':modules:infrastructure:api-query-jpa')?.name = 'api-query-jpa' include 'modules:infrastructure:log-writer' findProject(':modules:infrastructure:log-writer')?.name = 'log-writer' include 'modules:infrastructure:logging' -findProject(':modules:infrastructure:logging')?.name = 'logging' \ No newline at end of file +findProject(':modules:infrastructure:logging')?.name = 'logging' +include 'modules:master-api' +findProject(':modules:master-api')?.name = 'master-api' + From 8bd6c0aefa3f37cd6a3e0899bf71e83f2835c1e9 Mon Sep 17 00:00:00 2001 From: coco3x Date: Fri, 20 Dec 2024 23:54:50 +0900 Subject: [PATCH 06/22] =?UTF-8?q?chore:=20logback-spring.xml=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-logging.yml | 11 +++++++++++ .../logging/src/main/resources/logback-common.xml} | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 modules/infrastructure/logging/src/main/resources/application-logging.yml rename modules/{network-api/src/main/resources/logback-spring.xml => infrastructure/logging/src/main/resources/logback-common.xml} (100%) diff --git a/modules/infrastructure/logging/src/main/resources/application-logging.yml b/modules/infrastructure/logging/src/main/resources/application-logging.yml new file mode 100644 index 00000000..6d32dd44 --- /dev/null +++ b/modules/infrastructure/logging/src/main/resources/application-logging.yml @@ -0,0 +1,11 @@ +#TODO: 지금은 api 모듈들이 이 모듈을 공용으로 사용하지만 추후에 모듈마다 로깅 설정을 할 수 있도록 할 것 + +spring: + config: + import: + # @PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 + # 여기서 env를 미리 로드하여 logback-spring.xml에서 springProperty를 사용할 수 있도록 합니다. + - "classpath:env-logging.properties" +logging: + discord: + webhook-url: ${DISCORD_WEBHOOK_URL} \ No newline at end of file diff --git a/modules/network-api/src/main/resources/logback-spring.xml b/modules/infrastructure/logging/src/main/resources/logback-common.xml similarity index 100% rename from modules/network-api/src/main/resources/logback-spring.xml rename to modules/infrastructure/logging/src/main/resources/logback-common.xml index 1a02b89f..52db6a09 100644 --- a/modules/network-api/src/main/resources/logback-spring.xml +++ b/modules/infrastructure/logging/src/main/resources/logback-common.xml @@ -49,10 +49,6 @@ - - - - @@ -65,5 +61,9 @@ ${NO_COLOR_LOG_PATTERN} + + + + \ No newline at end of file From 5f1d81a00b1ea69e9306c7a9510a2ba4b57312f1 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 00:06:34 +0900 Subject: [PATCH 07/22] =?UTF-8?q?chore(master-api):=20yml=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-master-api.yml | 7 +++++++ modules/master-api/src/main/resources/application.yml | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 modules/master-api/src/main/resources/application-master-api.yml diff --git a/modules/master-api/src/main/resources/application-master-api.yml b/modules/master-api/src/main/resources/application-master-api.yml new file mode 100644 index 00000000..8117a8c8 --- /dev/null +++ b/modules/master-api/src/main/resources/application-master-api.yml @@ -0,0 +1,7 @@ +spring: + config: + import: + - "classpath:application-main-api.yml" + - "classpath:application-network-api.yml" +logging: + config: "classpath:logback-common.xml" \ No newline at end of file diff --git a/modules/master-api/src/main/resources/application.yml b/modules/master-api/src/main/resources/application.yml index 72893cbb..7e54b65a 100644 --- a/modules/master-api/src/main/resources/application.yml +++ b/modules/master-api/src/main/resources/application.yml @@ -1,7 +1,4 @@ spring: profiles: active: local - config: - import: - - "classpath:application-main-api.yml" - - "classpath:application-network-api.yml" \ No newline at end of file + include: master-api \ No newline at end of file From 798c45544fcd7f0d429ff7be5d856fbf2a0aae54 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 00:23:39 +0900 Subject: [PATCH 08/22] =?UTF-8?q?chore(main-api):=20logback-common.xml=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/main-api/build.gradle | 2 +- modules/main-api/src/main/resources/application-main-api.yml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/main-api/build.gradle b/modules/main-api/build.gradle index 40a62545..1011cd90 100644 --- a/modules/main-api/build.gradle +++ b/modules/main-api/build.gradle @@ -15,7 +15,7 @@ repositories { dependencies { implementation project(':modules:domain') - + implementation project(":modules:infrastructure:logging") //domain 구현 모듈 runtimeOnly project(":modules:infrastructure:domain-jpa") diff --git a/modules/main-api/src/main/resources/application-main-api.yml b/modules/main-api/src/main/resources/application-main-api.yml index 15415c91..c0be6de0 100644 --- a/modules/main-api/src/main/resources/application-main-api.yml +++ b/modules/main-api/src/main/resources/application-main-api.yml @@ -1,4 +1,6 @@ spring: config: #domain-jpa 모듈 - import: "classpath:application-domain-jpa.yml" \ No newline at end of file + import: "classpath:application-domain-jpa.yml" +logging: + config: "classpath:logback-common.xml" \ No newline at end of file From 565f6c643bb6466cedf4e45b93a30003735271c3 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 00:31:53 +0900 Subject: [PATCH 09/22] =?UTF-8?q?chore(master-api):=20logback-command.xml?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../master-api/src/main/resources/application-master-api.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/master-api/src/main/resources/application-master-api.yml b/modules/master-api/src/main/resources/application-master-api.yml index 8117a8c8..d485effe 100644 --- a/modules/master-api/src/main/resources/application-master-api.yml +++ b/modules/master-api/src/main/resources/application-master-api.yml @@ -2,6 +2,4 @@ spring: config: import: - "classpath:application-main-api.yml" - - "classpath:application-network-api.yml" -logging: - config: "classpath:logback-common.xml" \ No newline at end of file + - "classpath:application-network-api.yml" \ No newline at end of file From 1294c9f35417c122b11a8a98f7d3713129b3ac75 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 00:35:07 +0900 Subject: [PATCH 10/22] =?UTF-8?q?chore(network-api):=20logback-common.xml?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-network-api.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/network-api/src/main/resources/application-network-api.yml b/modules/network-api/src/main/resources/application-network-api.yml index f734875e..d4f4b01b 100644 --- a/modules/network-api/src/main/resources/application-network-api.yml +++ b/modules/network-api/src/main/resources/application-network-api.yml @@ -1,11 +1,7 @@ spring: config: import: - #@PropertySource는 스프링 컨텍스트가 초기화된 이후 처리되기 때문에 여기서 env를 미리 로드 - - "classpath:env-network-api.properties" #log-writer 모듈 - "classpath:application-log-writer.yml" - logging: - discord: - webhook-url: ${DISCORD_WEBHOOK_URL} \ No newline at end of file + config: "classpath:logback-common.xml" \ No newline at end of file From 3fbf1adbbefa5bf370c58abc212045e936ae7202 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 21:54:44 +0900 Subject: [PATCH 11/22] =?UTF-8?q?feat(domain-jpa):=20datasource=20?= =?UTF-8?q?=EB=94=B0=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain_jpa/config/DataSourceConfig.java | 99 +++++++++++++++++++ .../whoz_in/domain_jpa/config/JpaConfig.java | 9 +- .../application-domain-jpa-local.yml | 5 + .../main/resources/application-domain-jpa.yml | 17 ++-- 4 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java create mode 100644 modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa-local.yml diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java new file mode 100644 index 00000000..0f113c5d --- /dev/null +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java @@ -0,0 +1,99 @@ +package com.whoz_in.domain_jpa.config; + +import com.zaxxer.hikari.HikariDataSource; +import jakarta.persistence.EntityManagerFactory; +import java.util.Map; +import javax.sql.DataSource; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; + +@Configuration +@EnableJpaRepositories( + basePackages = "com.whoz_in.domain_jpa", + entityManagerFactoryRef = "domainJpaEntityManagerFactory", + transactionManagerRef = "domainJpaTransactionManager" +) +@RequiredArgsConstructor +public class DataSourceConfig { + //DB 연결 세팅값 객체 + //잠깐쓸거라 밖으로 빼지 않았음 + //설정마다 필드가 다를 수 있으므로 공통 모듈로 빼지 않았음 + @Getter + @Setter + public static class DataSourceProperties { + private String url; + private String username; + private String password; + private String driverClassName; + } + //하이버네이트 관련 설정값 객체 + @Getter + @Setter + public static class HibernateProperties { + private String ddlAuto; + private boolean formatSql; + private boolean showSql; + } + + //세팅값 객체를 빈으로 등록함 + //@Bean 메서드를 통해 자동으로 빈 등록이 되기 때문에 @ConfigurationPropertiesScan 없이도 동작함 + @Bean + @ConfigurationProperties("domain-jpa.datasource") + public DataSourceProperties domainJpaDataSourceProperties(){ + return new DataSourceProperties(); + } + @Bean + @ConfigurationProperties("domain-jpa.hibernate") + public HibernateProperties domainJpaHibernateProperties(){ + return new HibernateProperties(); + } + + //세팅값을 통해 DataSource 생성 + @Bean + public DataSource domainJpaDataSource(DataSourceProperties properties) { + HikariDataSource dataSource = new HikariDataSource(); + dataSource.setJdbcUrl(properties.getUrl()); + dataSource.setUsername(properties.getUsername()); + dataSource.setPassword(properties.getPassword()); + dataSource.setDriverClassName(properties.getDriverClassName()); + return dataSource; + } + + //JPA 설정 + @Bean + public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("domainJpaDataSource") DataSource dataSource, + @Qualifier("domainJpaHibernateProperties") HibernateProperties hibernateProperties) { + return builder + .dataSource(dataSource) //DataSource 지정 + .persistenceUnit("domain_jpa") //이름 + .packages("com.whoz_in.domain_jpa") //JPA 엔티티가 존재하는 패키지 + .properties( + Map.of( + "hibernate.hbm2ddl.auto", hibernateProperties.ddlAuto, + "hibernate.show_sql", hibernateProperties.showSql, + "hibernate.format_sql", hibernateProperties.formatSql + ) + ) + .build(); + } + + //트랜잭션 설정 + @Bean + public PlatformTransactionManager domainJpaTransactionManager( + @Qualifier("domainJpaEntityManagerFactory") EntityManagerFactory entityManagerFactory) { + //필요하면 설정 추가하기 + return new JpaTransactionManager(entityManagerFactory); + } +} \ No newline at end of file diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/JpaConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/JpaConfig.java index dc2e3732..ea2202f5 100644 --- a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/JpaConfig.java +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/JpaConfig.java @@ -1,15 +1,8 @@ package com.whoz_in.domain_jpa.config; -import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - @Configuration @EnableJpaAuditing -//기본적으로 SpringApplication 모듈에서 찾기 때문에 이 모듈에서도 찾을 수 있도록 함 -@EnableJpaRepositories(basePackages = {"com.whoz_in.domain_jpa"}) -@EntityScan(basePackages = "com.whoz_in") -public class JpaConfig { -} +public class JpaConfig {} diff --git a/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa-local.yml b/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa-local.yml new file mode 100644 index 00000000..d7f97627 --- /dev/null +++ b/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa-local.yml @@ -0,0 +1,5 @@ +domain-jpa: + hibernate: + ddl-auto: create + show_sql: true + format_sql: true diff --git a/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml b/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml index 89d151fd..d1729a5f 100644 --- a/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml +++ b/modules/infrastructure/domain-jpa/src/main/resources/application-domain-jpa.yml @@ -1,18 +1,17 @@ spring: + jpa: + open-in-view: false + +domain-jpa: datasource: url: ${DB_URL} username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: ${DB_DRIVER_CLASS} - jpa: - hibernate: - ddl-auto: create - properties: - hibernate: - format_sql: true - show_sql: true - generate-ddl: false - open-in-view: false + hibernate: + ddl-auto: validate + show_sql: false + logging: level: root: info From d70dbb5cfbe1cd99e555a4ba0d667585d05406d0 Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 22:54:38 +0900 Subject: [PATCH 12/22] =?UTF-8?q?fix:=20=EB=8B=A4=EB=A5=B8=20database?= =?UTF-8?q?=EC=9D=98=20datasource,=20jpa=20=EA=B4=80=EB=A0=A8=20=EB=B9=88?= =?UTF-8?q?=EC=9D=84=20=EB=93=B1=EB=A1=9D=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20Primary=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whoz_in/domain_jpa/config/DataSourceConfig.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java index 0f113c5d..54bd4c9a 100644 --- a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java @@ -12,6 +12,7 @@ import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -59,6 +60,7 @@ public HibernateProperties domainJpaHibernateProperties(){ } //세팅값을 통해 DataSource 생성 + @Primary @Bean public DataSource domainJpaDataSource(DataSourceProperties properties) { HikariDataSource dataSource = new HikariDataSource(); @@ -70,6 +72,7 @@ public DataSource domainJpaDataSource(DataSourceProperties properties) { } //JPA 설정 + @Primary @Bean public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( EntityManagerFactoryBuilder builder, @@ -90,6 +93,7 @@ public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( } //트랜잭션 설정 + @Primary @Bean public PlatformTransactionManager domainJpaTransactionManager( @Qualifier("domainJpaEntityManagerFactory") EntityManagerFactory entityManagerFactory) { From c214a53c3d6e3057eb38780ae50e4af40708c1dc Mon Sep 17 00:00:00 2001 From: coco3x Date: Sat, 21 Dec 2024 22:56:44 +0900 Subject: [PATCH 13/22] =?UTF-8?q?update(domain-jpa):=20=ED=9E=88=EC=B9=B4?= =?UTF-8?q?=EB=A6=AC=20=ED=92=80=20=EC=9D=B4=EB=A6=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whoz_in/domain_jpa/config/DataSourceConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java index 54bd4c9a..ffe0b74f 100644 --- a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java @@ -64,6 +64,7 @@ public HibernateProperties domainJpaHibernateProperties(){ @Bean public DataSource domainJpaDataSource(DataSourceProperties properties) { HikariDataSource dataSource = new HikariDataSource(); + dataSource.setPoolName("DomainJpaHikariPool"); dataSource.setJdbcUrl(properties.getUrl()); dataSource.setUsername(properties.getUsername()); dataSource.setPassword(properties.getPassword()); From 4c8d60f52c35e043ee0e9d9c36dc5fe154d6776d Mon Sep 17 00:00:00 2001 From: coco3x Date: Sun, 22 Dec 2024 01:40:42 +0900 Subject: [PATCH 14/22] =?UTF-8?q?fix:=20AOP=EB=A5=BC=20=EC=9C=84=ED=95=B4?= =?UTF-8?q?=20DAO=20=ED=81=B4=EB=9E=98=EC=8A=A4=20final=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/whoz_in/log_writer/managed/ManagedLogDAO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/ManagedLogDAO.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/ManagedLogDAO.java index b0081fc8..70c9794e 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/ManagedLogDAO.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/ManagedLogDAO.java @@ -15,7 +15,7 @@ @Slf4j @Component @RequiredArgsConstructor -public final class ManagedLogDAO { +public class ManagedLogDAO { private final JdbcTemplate jdbcTemplate; From 99fa9f379e344b85926930fd5810e75f3b9cb3dc Mon Sep 17 00:00:00 2001 From: coco3x Date: Sun, 22 Dec 2024 01:50:56 +0900 Subject: [PATCH 15/22] =?UTF-8?q?update(domain-jpa):=20TransactionManager?= =?UTF-8?q?=20@Primary=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whoz_in/domain_jpa/config/DataSourceConfig.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java index ffe0b74f..34e12de9 100644 --- a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java @@ -22,7 +22,7 @@ @EnableJpaRepositories( basePackages = "com.whoz_in.domain_jpa", entityManagerFactoryRef = "domainJpaEntityManagerFactory", - transactionManagerRef = "domainJpaTransactionManager" + transactionManagerRef = "domainJpaTM" ) @RequiredArgsConstructor public class DataSourceConfig { @@ -73,7 +73,6 @@ public DataSource domainJpaDataSource(DataSourceProperties properties) { } //JPA 설정 - @Primary @Bean public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( EntityManagerFactoryBuilder builder, @@ -93,9 +92,10 @@ public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( .build(); } - //트랜잭션 설정 - @Primary - @Bean + //TransactionManager가 여러 개인 경우 트랜잭션에서 알맞게 골라 사용해야 함 + //@Primary를 붙이면 t.m을 설정하지 않아도 알아서 골라버리므로 잘못된 t.m을 사용할 가능성이 있음 + //따라서 @Primary를 설정하지 않음으로써 t.m이 2개 이상 등록된 경우에 명시적으로 설정하도록 강제한다. + @Bean("domainJpaTM") public PlatformTransactionManager domainJpaTransactionManager( @Qualifier("domainJpaEntityManagerFactory") EntityManagerFactory entityManagerFactory) { //필요하면 설정 추가하기 From 23e1c142aab0dec812b42b66167b3ac4fe9e412c Mon Sep 17 00:00:00 2001 From: coco3x Date: Sun, 22 Dec 2024 01:51:44 +0900 Subject: [PATCH 16/22] =?UTF-8?q?feat(log-writer):=20datasource=20?= =?UTF-8?q?=EB=94=B0=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log_writer/config/DataSourceConfig.java | 55 +++++++++++++++++++ .../main/resources/application-log-writer.yml | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java new file mode 100644 index 00000000..c363c885 --- /dev/null +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java @@ -0,0 +1,55 @@ +package com.whoz_in.log_writer.config; + +import com.zaxxer.hikari.HikariDataSource; +import javax.sql.DataSource; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.transaction.PlatformTransactionManager; + +@Configuration("logWriterDataSourceConfig") +@RequiredArgsConstructor +public class DataSourceConfig { + @Getter + @Setter + public static class DataSourceProperties { + private String url; + private String username; + private String password; + private String driverClassName; + } + + @Bean + @ConfigurationProperties("log-writer.datasource") + public DataSourceProperties logWriterDataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + public DataSource logWriterDataSource(DataSourceProperties properties) { + HikariDataSource dataSource = new HikariDataSource(); + dataSource.setPoolName("LogWriterHikariPool"); + dataSource.setJdbcUrl(properties.getUrl()); + dataSource.setUsername(properties.getUsername()); + dataSource.setPassword(properties.getPassword()); + dataSource.setDriverClassName(properties.getDriverClassName()); + return dataSource; + } + + @Bean + public JdbcTemplate logWriterJdbcTemplate(@Qualifier("logWriterDataSource") DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + + // 트랜잭션 매니저 - 아직은 쓸모 없는거 같아서 등록 안했음 + @Bean("logWriterTM") + public PlatformTransactionManager logWriterTransactionManager(@Qualifier("logWriterDataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } +} diff --git a/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml b/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml index eccd2719..92330d71 100644 --- a/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml +++ b/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml @@ -1,4 +1,4 @@ -spring: +log-writer: datasource: url: ${DB_URL} username: ${DB_USERNAME} From 0973a07b141abceebe085057513313ecb14c8302 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 05:44:34 +0900 Subject: [PATCH 17/22] =?UTF-8?q?depend(main-api):=20spring=20transaction?= =?UTF-8?q?=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/main-api/build.gradle | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/main-api/build.gradle b/modules/main-api/build.gradle index 1011cd90..03c2a7c2 100644 --- a/modules/main-api/build.gradle +++ b/modules/main-api/build.gradle @@ -12,25 +12,30 @@ jar.enabled = true repositories { mavenCentral() } - dependencies { + implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' +// implementation 'org.springframework.boot:spring-boot-starter-security' + + //transaction + implementation 'org.springframework:spring-tx' + + //domain implementation project(':modules:domain') + runtimeOnly project(":modules:infrastructure:domain-jpa") // 구현 모듈 + + //logging implementation project(":modules:infrastructure:logging") - //domain 구현 모듈 - runtimeOnly project(":modules:infrastructure:domain-jpa") //main-api 구현 모듈 (runtimeOnly - 순환 의존 방지) runtimeOnly project(":modules:infrastructure:spring") runtimeOnly project(":modules:infrastructure:api-query-jpa") - implementation 'org.springframework.boot:spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-web' -// implementation 'org.springframework.boot:spring-boot-starter-security' - testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter' } + test { useJUnitPlatform() } \ No newline at end of file From 86e3d4080ea99ff8c6279f1f27679f9bcd163763 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 05:45:35 +0900 Subject: [PATCH 18/22] =?UTF-8?q?fix(main-api):=20AOP=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20final=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main_api/command/device/application/DeviceAddHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceAddHandler.java b/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceAddHandler.java index 5e99c154..a1033d27 100644 --- a/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceAddHandler.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceAddHandler.java @@ -10,7 +10,7 @@ @Handler @RequiredArgsConstructor -public final class DeviceAddHandler extends CommandHandler { +public class DeviceAddHandler extends CommandHandler { private final RequesterInfo requesterInfo; private final DeviceRepository repository; private final EventBus eventBus; From c59b233cd7de1f998ef7cc776cbd2ec5076833f9 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 06:32:39 +0900 Subject: [PATCH 19/22] =?UTF-8?q?fix:=20AOP=EA=B0=80=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=EB=90=9C=20Handler=20=ED=94=84=EB=A1=9D=EC=8B=9C=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/application/command/CommandHandlers.java | 7 +++++-- .../whoz_in/spring/application/query/QueryHandlers.java | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java index 85e54f60..657c7263 100644 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java +++ b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java @@ -3,8 +3,10 @@ import com.whoz_in.main_api.shared.application.command.Command; import com.whoz_in.main_api.shared.application.command.CommandHandler; import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.Map; import java.util.stream.Collectors; +import org.springframework.aop.framework.AopProxyUtils; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -23,8 +25,9 @@ public CommandHandlers(ApplicationContext context) { .collect( Collectors.toMap( commandHandler -> { - Class handlerClass = commandHandler.getClass(); - ParameterizedType paramType = (ParameterizedType) handlerClass.getGenericSuperclass(); + //commandHandler의 프록시 객체를 가져옴 (예시 - @Transactional 사용 시) + Class targetClass = AopProxyUtils.ultimateTargetClass(commandHandler); + ParameterizedType paramType = (ParameterizedType) targetClass.getGenericSuperclass(); return (Class) paramType.getActualTypeArguments()[0]; }, commandHandler -> commandHandler diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java index 84523a1c..22412a1b 100644 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java +++ b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java @@ -5,6 +5,7 @@ import java.lang.reflect.ParameterizedType; import java.util.Map; import java.util.stream.Collectors; +import org.springframework.aop.framework.AopProxyUtils; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -19,8 +20,9 @@ public QueryHandlers(ApplicationContext context) { .collect( Collectors.toMap( queryHandler -> { - Class handlerClass = queryHandler.getClass(); - ParameterizedType paramType = (ParameterizedType) handlerClass.getGenericSuperclass(); + //queryHandler의 프록시 객체를 가져옴 (예시 - @Transactional 사용 시) + Class targetClass = AopProxyUtils.ultimateTargetClass(queryHandler); + ParameterizedType paramType = (ParameterizedType) targetClass.getGenericSuperclass(); return (Class) paramType.getActualTypeArguments()[0]; }, queryHandler -> queryHandler From 999fb000e126a3577e7e20618f55692d0e225915 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 07:19:56 +0900 Subject: [PATCH 20/22] =?UTF-8?q?chore:=20spring=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CommandHandlers는 스프링을 사용하는 이상 다른 방식으로 구현될 일이 없기 때문에 api 모듈의 것이 맞다고 판단 기존에 구현된 CommandBus(InMemory)는 단일 서버인 main-api가 기본으로 사용하기 때문에 api에 있는 것이 맞다고 판단 --- modules/infrastructure/spring/build.gradle | 22 ------------------ .../application/command/SpringCommandBus.java | 23 ------------------- .../application/query/SpringQueryBus.java | 20 ---------------- modules/main-api/build.gradle | 1 - .../application/command/CommandBus.java | 3 +-- .../application/command/CommandHandlers.java | 8 ++----- .../command/InMemoryCommandBus.java | 17 ++++++++++++++ .../application/query/InMemoryQueryBus.java | 16 +++++++++++++ .../application/query/QueryHandlers.java | 4 +--- .../domain}/SpringApplicationEventBus.java | 4 ++-- settings.gradle | 2 -- 11 files changed, 39 insertions(+), 81 deletions(-) delete mode 100644 modules/infrastructure/spring/build.gradle delete mode 100644 modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/SpringCommandBus.java delete mode 100644 modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/SpringQueryBus.java rename modules/{infrastructure/spring/src/main/java/com/whoz_in/spring => main-api/src/main/java/com/whoz_in/main_api/shared}/application/command/CommandHandlers.java (81%) create mode 100644 modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/InMemoryCommandBus.java create mode 100644 modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/InMemoryQueryBus.java rename modules/{infrastructure/spring/src/main/java/com/whoz_in/spring => main-api/src/main/java/com/whoz_in/main_api/shared}/application/query/QueryHandlers.java (91%) rename modules/{infrastructure/spring/src/main/java/com/whoz_in/spring/domain/event => main-api/src/main/java/com/whoz_in/main_api/shared/domain}/SpringApplicationEventBus.java (81%) diff --git a/modules/infrastructure/spring/build.gradle b/modules/infrastructure/spring/build.gradle deleted file mode 100644 index ef66c2d9..00000000 --- a/modules/infrastructure/spring/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.Whoz-In' -version = '0.0.1-SNAPSHOT' - -repositories { - mavenCentral() -} - -dependencies { - compileOnly project(':modules:domain') - compileOnly project(':modules:main-api') - - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/SpringCommandBus.java b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/SpringCommandBus.java deleted file mode 100644 index 46bc2aad..00000000 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/SpringCommandBus.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.whoz_in.spring.application.command; - -import com.whoz_in.main_api.shared.application.command.Command; -import com.whoz_in.main_api.shared.application.command.CommandBus; -import com.whoz_in.main_api.shared.application.command.CommandHandler; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -/* -스프링 컨텍스트 내의 핸들러를 찾아 바로 호출하도록 구현되었으므로 동기적으로 동작합니다. - */ -@Component -@RequiredArgsConstructor -public final class SpringCommandBus implements CommandBus { - private final CommandHandlers handlers; - - @Override - public void dispatch(Command command){ - CommandHandler handler = handlers.findBy(command); - handler.handle(command); - } -} - diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/SpringQueryBus.java b/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/SpringQueryBus.java deleted file mode 100644 index 5c3a7620..00000000 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/SpringQueryBus.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.whoz_in.spring.application.query; - -import com.whoz_in.main_api.shared.application.query.Query; -import com.whoz_in.main_api.shared.application.query.QueryBus; -import com.whoz_in.main_api.shared.application.query.QueryHandler; -import com.whoz_in.main_api.shared.application.query.Response; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public final class SpringQueryBus implements QueryBus { - private final QueryHandlers handlers; - - @Override - public R ask(Query query){ - QueryHandler handler = handlers.findBy(query); - return handler.handle(query); - } -} diff --git a/modules/main-api/build.gradle b/modules/main-api/build.gradle index 03c2a7c2..17bb4709 100644 --- a/modules/main-api/build.gradle +++ b/modules/main-api/build.gradle @@ -28,7 +28,6 @@ dependencies { implementation project(":modules:infrastructure:logging") //main-api 구현 모듈 (runtimeOnly - 순환 의존 방지) - runtimeOnly project(":modules:infrastructure:spring") runtimeOnly project(":modules:infrastructure:api-query-jpa") testImplementation platform('org.junit:junit-bom:5.9.1') diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandBus.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandBus.java index 962f5176..fba5f365 100644 --- a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandBus.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandBus.java @@ -1,8 +1,7 @@ package com.whoz_in.main_api.shared.application.command; /* -받은 Command에 따라 적절한 CommandHandler에게 명령을 전달하는 인터페이스. -적절한 CommandHandler를 찾는 로직은 이 구현체가 담당해야 한다. +받은 Command에 따라 적절한 CommandHandler에게 명령을 전달하는 인터페이스이다. */ public interface CommandBus { void dispatch(Command command); diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandHandlers.java similarity index 81% rename from modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java rename to modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandHandlers.java index 657c7263..3be3911f 100644 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/command/CommandHandlers.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/CommandHandlers.java @@ -1,9 +1,6 @@ -package com.whoz_in.spring.application.command; +package com.whoz_in.main_api.shared.application.command; -import com.whoz_in.main_api.shared.application.command.Command; -import com.whoz_in.main_api.shared.application.command.CommandHandler; import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.util.Map; import java.util.stream.Collectors; import org.springframework.aop.framework.AopProxyUtils; @@ -11,8 +8,7 @@ import org.springframework.stereotype.Component; /* -Command를 받으면 해당 Command를 처리할 수 있는 CommandHandler를 제공하는 클래스입니다. -스프링 컨텍스트를 이용하여 구현되었습니다. +Command를 받아 해당 Command를 처리할 수 있는 CommandHandler를 제공하는 클래스입니다. */ @Component public final class CommandHandlers { diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/InMemoryCommandBus.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/InMemoryCommandBus.java new file mode 100644 index 00000000..26d92809 --- /dev/null +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/command/InMemoryCommandBus.java @@ -0,0 +1,17 @@ +package com.whoz_in.main_api.shared.application.command; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public final class InMemoryCommandBus implements CommandBus { + private final CommandHandlers handlers; + + @Override + public void dispatch(Command command){ + CommandHandler handler = handlers.findBy(command); + handler.handle(command); + } +} + diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/InMemoryQueryBus.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/InMemoryQueryBus.java new file mode 100644 index 00000000..ba09623a --- /dev/null +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/InMemoryQueryBus.java @@ -0,0 +1,16 @@ +package com.whoz_in.main_api.shared.application.query; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public final class InMemoryQueryBus implements QueryBus { + private final QueryHandlers handlers; + + @Override + public R ask(Query query){ + QueryHandler handler = handlers.findBy(query); + return handler.handle(query); + } +} diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/QueryHandlers.java similarity index 91% rename from modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java rename to modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/QueryHandlers.java index 22412a1b..19dad58d 100644 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/application/query/QueryHandlers.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/application/query/QueryHandlers.java @@ -1,7 +1,5 @@ -package com.whoz_in.spring.application.query; +package com.whoz_in.main_api.shared.application.query; -import com.whoz_in.main_api.shared.application.query.Query; -import com.whoz_in.main_api.shared.application.query.QueryHandler; import java.lang.reflect.ParameterizedType; import java.util.Map; import java.util.stream.Collectors; diff --git a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/domain/event/SpringApplicationEventBus.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/SpringApplicationEventBus.java similarity index 81% rename from modules/infrastructure/spring/src/main/java/com/whoz_in/spring/domain/event/SpringApplicationEventBus.java rename to modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/SpringApplicationEventBus.java index 488b4493..4b4daabb 100644 --- a/modules/infrastructure/spring/src/main/java/com/whoz_in/spring/domain/event/SpringApplicationEventBus.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/SpringApplicationEventBus.java @@ -1,4 +1,4 @@ -package com.whoz_in.spring.domain.event; +package com.whoz_in.main_api.shared.domain; import com.whoz_in.domain.shared.event.DomainEvent; import com.whoz_in.domain.shared.event.EventBus; @@ -10,7 +10,7 @@ /* 기본적인 이벤트 퍼블리셔 -추후에 카프카나 토끼MQ를 공부하면 새로운 구현체를 만들어봅시다. +추후에 카프카나 Rabbit MQ를 공부하면 새로운 구현체를 만들어봅시다. */ @Service @RequiredArgsConstructor diff --git a/settings.gradle b/settings.gradle index f82982df..380a2b55 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,8 +7,6 @@ include 'modules:domain' findProject(':modules:domain')?.name = 'domain' include 'modules:infrastructure:domain-jpa' findProject(':modules:infrastructure:domain-jpa')?.name = 'domain-jpa' -include 'modules:infrastructure:spring' -findProject(':modules:infrastructure:spring')?.name = 'spring' include 'modules:infrastructure:api-query-jpa' findProject(':modules:infrastructure:api-query-jpa')?.name = 'api-query-jpa' include 'modules:infrastructure:log-writer' From 3e2c01cdea947b386693cc8cd189e3425eb9e147 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 07:38:39 +0900 Subject: [PATCH 21/22] =?UTF-8?q?update:=20@PropertySource=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20spring.config.import=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/whoz_in/log_writer/config/PropertiesConfig.java | 9 --------- .../src/main/resources/application-log-writer.yml | 6 ++++++ 2 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/PropertiesConfig.java diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/PropertiesConfig.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/PropertiesConfig.java deleted file mode 100644 index 48c7c6fd..00000000 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/PropertiesConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.whoz_in.log_writer.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -@Configuration("logWriterPropertiesConfig") -@PropertySource("classpath:/env-log-writer.properties") -public class PropertiesConfig { -} diff --git a/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml b/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml index 92330d71..f7fea0ff 100644 --- a/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml +++ b/modules/infrastructure/log-writer/src/main/resources/application-log-writer.yml @@ -1,7 +1,13 @@ +spring: + config: + import: + - "classpath:env-log-writer.properties" + log-writer: datasource: url: ${DB_URL} username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: ${DB_DRIVER_CLASS} + sudo_password: ${SUDO_PASSWORD} \ No newline at end of file From 99051dcf82c4fcab41f07f7031680fd3a2e20f30 Mon Sep 17 00:00:00 2001 From: coco3x Date: Mon, 23 Dec 2024 20:31:55 +0900 Subject: [PATCH 22/22] =?UTF-8?q?test(log-writer):=20log-writer=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20@Transaction?= =?UTF-8?q?al=EC=9D=80=20log-writer=EC=9D=98=20transactionManager=EB=A5=BC?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=ED=95=B4=EC=95=BC=20=ED=95=A9=EB=8B=88?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain_jpa/config/DataSourceConfig.java | 5 +- .../log_writer/config/DataSourceConfig.java | 3 +- .../LogWriterTransactionManagerTest.java | 57 +++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 modules/infrastructure/log-writer/src/test/java/com/whoz_in/log_writer/archtect/LogWriterTransactionManagerTest.java diff --git a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java index 34e12de9..8a859e02 100644 --- a/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java +++ b/modules/infrastructure/domain-jpa/src/main/java/com/whoz_in/domain_jpa/config/DataSourceConfig.java @@ -73,6 +73,7 @@ public DataSource domainJpaDataSource(DataSourceProperties properties) { } //JPA 설정 + @Primary @Bean public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( EntityManagerFactoryBuilder builder, @@ -92,9 +93,7 @@ public LocalContainerEntityManagerFactoryBean domainJpaEntityManagerFactory( .build(); } - //TransactionManager가 여러 개인 경우 트랜잭션에서 알맞게 골라 사용해야 함 - //@Primary를 붙이면 t.m을 설정하지 않아도 알아서 골라버리므로 잘못된 t.m을 사용할 가능성이 있음 - //따라서 @Primary를 설정하지 않음으로써 t.m이 2개 이상 등록된 경우에 명시적으로 설정하도록 강제한다. + @Primary @Bean("domainJpaTM") public PlatformTransactionManager domainJpaTransactionManager( @Qualifier("domainJpaEntityManagerFactory") EntityManagerFactory entityManagerFactory) { diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java index c363c885..f903f4b2 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/config/DataSourceConfig.java @@ -16,6 +16,7 @@ @Configuration("logWriterDataSourceConfig") @RequiredArgsConstructor public class DataSourceConfig { + public static final String LOG_WRITER_TRANSACTION_MANAGER = "logWriterTransactionManager"; @Getter @Setter public static class DataSourceProperties { @@ -48,7 +49,7 @@ public JdbcTemplate logWriterJdbcTemplate(@Qualifier("logWriterDataSource") Data } // 트랜잭션 매니저 - 아직은 쓸모 없는거 같아서 등록 안했음 - @Bean("logWriterTM") + @Bean(LOG_WRITER_TRANSACTION_MANAGER) public PlatformTransactionManager logWriterTransactionManager(@Qualifier("logWriterDataSource") DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } diff --git a/modules/infrastructure/log-writer/src/test/java/com/whoz_in/log_writer/archtect/LogWriterTransactionManagerTest.java b/modules/infrastructure/log-writer/src/test/java/com/whoz_in/log_writer/archtect/LogWriterTransactionManagerTest.java new file mode 100644 index 00000000..8f55f2c4 --- /dev/null +++ b/modules/infrastructure/log-writer/src/test/java/com/whoz_in/log_writer/archtect/LogWriterTransactionManagerTest.java @@ -0,0 +1,57 @@ +package com.whoz_in.log_writer.archtect; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; +import static com.whoz_in.log_writer.config.DataSourceConfig.LOG_WRITER_TRANSACTION_MANAGER; + +import com.tngtech.archunit.core.domain.JavaClasses; +import com.tngtech.archunit.core.domain.JavaMethod; +import com.tngtech.archunit.core.importer.ClassFileImporter; +import com.tngtech.archunit.lang.ArchCondition; +import com.tngtech.archunit.lang.ArchRule; +import com.tngtech.archunit.lang.ConditionEvents; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; + + +class LogWriterTransactionManagerTest { + + //@Transactional를 사용할 때 transactionManager를 DataSourceConfig.LOG_WRITER_TRANSACTION_MANAGER로 명시해야 한다 + @Test + void Transactional_어노테이션은_logWriterTransactionManager를_사용해야합니다() { + JavaClasses importedClasses = new ClassFileImporter().importPackages("com.whoz_in.log_writer"); + ArchRule rule = methods() + .that().areAnnotatedWith(Transactional.class) + .should(validateTransactionManager()) + .allowEmptyShould(true); + + rule.check(importedClasses); + } + + private static ArchCondition validateTransactionManager() { + return new ArchCondition<>("use logWriterTransactionManager") { + @Override + public void check(JavaMethod method, ConditionEvents events) { + // 메서드에 붙은 어노테이션 가져오기 + Transactional transactionalAnnotation = method.reflect() + .getAnnotation(Transactional.class); + + // 어노테이션이 존재하는지 + if (transactionalAnnotation != null) { + String transactionManager = Optional.of( + transactionalAnnotation.transactionManager()) + .filter(tm -> !tm.isBlank()) + .orElse(transactionalAnnotation.value()); + if (!transactionManager.equals(LOG_WRITER_TRANSACTION_MANAGER)) { + throw new AssertionError(String.format( + "%s - %s의 transactionManager가 '%s'임", + method.getOwner().getName(), + method.getName(), + transactionManager + )); + } + } + } + }; + } +}