한마디로
Spring Cloud Config는 분산 환경에서 설정정보를 관리 및 공유하기 위한 솔루션이다.
좀 더 자세히 말한다면마디로
Config Server로 설정정보를 중앙 관리하고 Config Client를 통해 설정정보에 접근한다. 실행 프로파일(개발/검증/운영, spring.profiles)별로 설정정보를 구성할 수 있으며 서버 재시작 없이 설정정보를 변경 및 전파할 수 있다.
출처: http://kubecloud.io/guide-spring-cloud-config/
설정정보를 Git Repository에 저장해두고 Config Server는 Git Repository를 바라보며, 각 Service들은 Config Server로부터 자신들의 설정정보를 제공 받는다. 관리자에 의해 Git Repository의 설정정보가 수정되면 Config Server는 이를 감지하여 갱신하며, 각 Service들은 재시작없이 Refresh 만으로 자신들의 설정정보를 갱신한다.
Config Server
maven
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
application.properties
server.port=8888
spring.cloud.config.server.git.uri=https://github.com/jangdaewon/survey
AWS specific
https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#authentication-with-aws-codecommit http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
Java system properties
- -Daws.accessKeyId
- -Daws.secretKey
Environment variables
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
https://github.com/jangdaewon/survey/account-service.yml
dwjang:
greeting: "hello spring cloud config"
---
spring:
profiles: stage
dwjang:
greeting: "stage - hello spring cloud config"
---
spring:
profiles: dev
dwjang:
greeting: "dev - hello spring cloud config"
---
spring:
profiles: local
dwjang:
greeting: "local - hello spring cloud config"
java
@SpringBootApplication
@EnableConfigServer
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
Config Client
maven
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
bootstrap.properties
spring.application.name=account-service
spring.cloud.config.uri=http://localhost:8888
#management.port=8081
#management.address=127.0.0.1
management.security.enabled=false
or VM Options -Dspring.cloud.config.uri
java
@RefreshScope
@RestController
public class AccountController {
@Value("${dwjang.greeting}")
private String greeting;
@RequestMapping(value = "/accounts", method = RequestMethod.GET)
public String accounts() {
return greeting;
}
}
VM Option
- -Dspring.profiles.active=dev
URL
참조
http://devguide.tistory.com/m/entry/%EC%A0%9C1%EC%9E%A5-Cloud-Config-%EA%B0%9C%EC%9A%94 http://kubecloud.io/guide-spring-cloud-config/ https://cloud.spring.io/spring-cloud-config/ http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.2.2.RELEASE/