Merge list property

This commit is contained in:
woozu.shin 2021-10-18 14:35:16 +09:00
parent d330bc8df9
commit c3e6e72e55
7 changed files with 85 additions and 13 deletions

View File

@ -1,16 +1,19 @@
package com.kakaoent.cpdd.config.client1.configuration.properties; package com.kakaoent.cpdd.config.client1.configuration.properties;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Setter
@Getter @Getter
@Component @Component
@ConfigurationProperties(prefix = "apis") public class ApiProperties implements ConfigApiProperties {
public class ApiProperties {
private String gateway; // client config List<ApiProperty> units;
private String point; // server config
public ApiProperties(List<ConfigApiProperties> apiProperties) {
units = new ArrayList<>();
apiProperties.forEach(e -> units.addAll(e.getUnits()));
}
} }

View File

@ -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<ApiProperty> units;
}

View File

@ -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<ApiProperty> 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);
}
}

View File

@ -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<ApiProperty> units;
}

View File

@ -18,12 +18,12 @@ public class PropertyAPIController {
@GetMapping("/apis/gateway") @GetMapping("/apis/gateway")
public Mono<String> getGatewayUrl() { public Mono<String> getGatewayUrl() {
return Mono.just(apiProperties.getGateway()); return Mono.just(apiProperties.find("gateway").getUrl());
} }
@GetMapping("/apis/point") @GetMapping("/apis/point")
public Mono<String> getPointAPIUrl() { public Mono<String> getPointAPIUrl() {
return Mono.just(apiProperties.getPoint()); return Mono.just(apiProperties.find("point").getUrl());
} }
} }

View File

@ -3,5 +3,8 @@ spring:
activate: activate:
on-profile: dev on-profile: dev
apis: api:
gateway: http://gw.application-dev.com clientconfig:
units:
- unit-name: gateway
url: http://gw.application-dev.com

View File

@ -2,5 +2,9 @@ spring:
config: config:
activate: activate:
on-profile: prod on-profile: prod
apis:
gateway: http://gw.application.com api:
clientconfig:
units:
- unit-name: gateway
url: http://gw.application.com