보통은 spring cloud config를 사용하는 이유가 분산 시스템에서 애플리케이션 설정을 중앙에서 관리하기 위해서인데
몇몇 케이스에는 server와 client를 같이 띄워야 할 경우도 있다.
이러한 상황에서 어떻게 설정해야 하는지 알아보자.
공식문서의 링크 : https://docs.spring.io/spring-cloud-config/reference/server/embedding.html
(Embedding the Config Server)
spring.cloud.config.server.bootstrap
spring.cloud.config.server.bootstrap true로 설정(기본값은 false)
해당 값은 application.yml 파일이 아닌 bootstrap.yml에 해줘야 한다.
If you use the bootstrap flag, the config server needs to have its name and repository URI configured in bootstrap.yml.
bootstrap.yml은 Spring Boot 애플리케이션이 초기 부팅(Bootstrapping)될 때 가장 먼저 로드되는 설정 파일이다.
composite environment repository configuration
spring.cloud.config.server.bootstrap true를 사용하는 경우 반드시 composite environment repository configuration를 사용해야 한다.
When setting spring.cloud.config.server.bootstrap to true you must also use a composite environment repository configuration.
왜인지는 정확하게 모르겠지만, 이유를 찾아보았을 때는 아래와 같다
- 단일 저장소(git, native 등)만 지정하면 Config Server가 자기 자신을 호출하는 문제 발생 가능
- composite을 사용하면 장애 발생 시 대체 저장소로 failover 가능
# bootstrap.yml
spring:
cloud:
config:
server:
bootstrap: true # Config Server도 설정을 외부에서 가져오도록 지정
composite:
- type: git
uri: https://github.com/my-org/config-repo
- type: native
search-locations: file:/etc/config
fail-on-composite-error: false
profile: alpha
name: apptest
label: main