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