From c3e6e72e555d77135e85ed28006cb7123a58d210 Mon Sep 17 00:00:00 2001 From: "woozu.shin" Date: Mon, 18 Oct 2021 14:35:16 +0900 Subject: [PATCH] Merge list property --- .../properties/ApiProperties.java | 17 +++++++----- .../properties/ClientConfigApiProperties.java | 18 +++++++++++++ .../properties/ConfigApiProperties.java | 26 +++++++++++++++++++ .../properties/ServerConfigApiProperties.java | 18 +++++++++++++ .../controller/PropertyAPIController.java | 4 +-- src/main/resources/application-dev.yml | 7 +++-- src/main/resources/application-prod.yml | 8 ++++-- 7 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ClientConfigApiProperties.java create mode 100644 src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ConfigApiProperties.java create mode 100644 src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ServerConfigApiProperties.java diff --git a/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ApiProperties.java b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ApiProperties.java index d51b11d..b2b58d3 100644 --- a/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ApiProperties.java +++ b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ApiProperties.java @@ -1,16 +1,19 @@ package com.kakaoent.cpdd.config.client1.configuration.properties; +import java.util.ArrayList; +import java.util.List; import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; -@Setter @Getter @Component -@ConfigurationProperties(prefix = "apis") -public class ApiProperties { - private String gateway; // client config - private String point; // server config +public class ApiProperties implements ConfigApiProperties { + + List units; + + public ApiProperties(List apiProperties) { + units = new ArrayList<>(); + apiProperties.forEach(e -> units.addAll(e.getUnits())); + } } diff --git a/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ClientConfigApiProperties.java b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ClientConfigApiProperties.java new file mode 100644 index 0000000..cf94969 --- /dev/null +++ b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ClientConfigApiProperties.java @@ -0,0 +1,18 @@ +package com.kakaoent.cpdd.config.client1.configuration.properties; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Setter +@Getter +@Component +@ConfigurationProperties(prefix = "api.clientconfig") +public class ClientConfigApiProperties implements ConfigApiProperties { + + private List units; + + +} diff --git a/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ConfigApiProperties.java b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ConfigApiProperties.java new file mode 100644 index 0000000..caa198d --- /dev/null +++ b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ConfigApiProperties.java @@ -0,0 +1,26 @@ +package com.kakaoent.cpdd.config.client1.configuration.properties; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; + +public interface ConfigApiProperties { + + List getUnits(); + + @Getter + @Setter + class ApiProperty { + + private String unitName; + private String url; + } + + default ApiProperty find(String unitName) { + return getUnits().stream() + .filter(e -> e.getUnitName().equals(unitName)) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } + +} diff --git a/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ServerConfigApiProperties.java b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ServerConfigApiProperties.java new file mode 100644 index 0000000..5f6f9a5 --- /dev/null +++ b/src/main/java/com/kakaoent/cpdd/config/client1/configuration/properties/ServerConfigApiProperties.java @@ -0,0 +1,18 @@ +package com.kakaoent.cpdd.config.client1.configuration.properties; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Setter +@Getter +@Component +@ConfigurationProperties(prefix = "api.serverconfig") +public class ServerConfigApiProperties implements ConfigApiProperties { + + private List units; + + +} diff --git a/src/main/java/com/kakaoent/cpdd/config/client1/controller/PropertyAPIController.java b/src/main/java/com/kakaoent/cpdd/config/client1/controller/PropertyAPIController.java index 9e9cbca..8bc4423 100644 --- a/src/main/java/com/kakaoent/cpdd/config/client1/controller/PropertyAPIController.java +++ b/src/main/java/com/kakaoent/cpdd/config/client1/controller/PropertyAPIController.java @@ -18,12 +18,12 @@ public class PropertyAPIController { @GetMapping("/apis/gateway") public Mono getGatewayUrl() { - return Mono.just(apiProperties.getGateway()); + return Mono.just(apiProperties.find("gateway").getUrl()); } @GetMapping("/apis/point") public Mono getPointAPIUrl() { - return Mono.just(apiProperties.getPoint()); + return Mono.just(apiProperties.find("point").getUrl()); } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 56737a6..f535bc9 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -3,5 +3,8 @@ spring: activate: on-profile: dev -apis: - gateway: http://gw.application-dev.com \ No newline at end of file +api: + clientconfig: + units: + - unit-name: gateway + url: http://gw.application-dev.com \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 27cb429..74ad418 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -2,5 +2,9 @@ spring: config: activate: on-profile: prod -apis: - gateway: http://gw.application.com \ No newline at end of file + +api: + clientconfig: + units: + - unit-name: gateway + url: http://gw.application.com \ No newline at end of file