Spring Cloud Config

spring cloud의 Config server 세팅에 대한 맛보기 정도 입니다. git repository, aws를 이용하는 법 등은 레퍼런스를 참고하시기 바랍니다.

### 레퍼런스
[Spring Cloud Config](https://docs.spring.io/spring-cloud-config/reference/index.html) 

## 파일경로로 세팅해보기
### resources 폴더의 폴더 구조
"[애플리케이션명]-[profile1].yml" 파일 내용은 알아서 작성해주세요

```
src
	main
		resources
			[애플리케이션명]
				[애플리케이션명]-[profile1].yml
				[애플리케이션명]-[profile2].yml
		application.yml
		bootstrap.yml
```

### bootstrap.yml
encrypt 설정은 bootstrap.yml에 세팅해줘야함

```
spring:
  application:
    name: configserver
  cloud:
    config:
      server:
        encrypt.enabled: false
```

### application.yml
[파일경로]는 '폴더구조'에서 [애플리케이션명] 까지 경로를 적어주면 됨. 따라서 파일경로로 설정파일 구성시 반드시 'resources' 폴더 안쪽에 넣을 필요는 없음. 이거는 그냥 로컬에서 테스트하기 위해 'resources' 폴더 안쪽에 넣어둔것임. 

```
server:
  port: 8888
spring:
  profiles:
    active: native
spring.cloud.config.server.native.search-locations: file://[파일경로]
```

### @EnableConfigServer 설정

```
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigServerApplication.class, args);
	}
}
```

### url로 설정정보 가져와 보기
브라우저에서 다음과 같이 호출해보면

```
http://localhost:8888/[애플리케이션명]/[profile1]
```

아래처럼 나올 것임. "propertySources" 에 값이 안 나오면 실패한 것임.

```
{
	"name":"simple",
	"profiles":["local"],
	"label":null,
	"version":null,
	"state":null,
	"propertySources":[
		{"name":"[파일경로]",
		"source":{"document":"server.port=8080 
				spring.application.name=[애플리케이션명].profile=[프로파일명]"}}
	]
}
```

댓글

이 블로그의 인기 게시물

Session 대신 JWT를 사용하는 이유

VSCode에서의 VIM 단축키와 키보드 구매 가이드

우분투에서 테스트링크(testlink)와 맨티스(mantis)로 테스팅 서버 구성하기