spring cloud config를 살펴보니..  4가지 정도가 주의하면 좋을 것 같다.


1. 
Spring Cloud(Boot) 주요 클래스에 @EnableConfigServer를 붙이기


@RestController
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

@RequestMapping(value = "/")
public @ResponseBody String root() {
return "Global Config Server";
}

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



2. 

설정 이름 주의하기

yaml 파일의 이름을

${ApplicationName}-${EnvironmentName}.yml로 설정해야 한다.


즉 아래와 같은 형태로 되어야 spring cloud config 설정을 확인할 수 있다. 

global-beta.yml

order-alpha.yml


따라서


http://localhot:8080/global/beta 

http://localhot:8080/order/alpha 이렇게 접근할 수 있다.




3. 

private 저장소의 경우 암호를 넣어야 한다.

spring.cloud.config.server.git.username=google-lab
spring.cloud.config.server.git.password=lab1234



4. 

spring cloud git url을 설정할 때 root 주소로 접근해야지 git 저장소의 sub directory에 접근하려고 하면 파싱 에러(org.eclipse.jgit.api.errors.TransportException: invalid advertisement of) 가 난다. 


이렇게 하지 말고

spring.cloud.config.server.git.uri=https://github.com/google/internal-config/config


아래와 같이 저장소 로 접근해야 한다.

spring.cloud.config.server.git.uri=https://github.com/google/internal-config


runtime 에러에서 final int tab = line.indexOf('\t'); 부분에서 에러가 발생한 것을 확인할 수 있다.

package org.eclipse.jgit.transport;

public class TransportHttp extends HttpTransport implements WalkTransport,

PackTransport {


Map<String, Ref> readAdvertisedImpl(final BufferedReader br)

throws IOException, PackProtocolException {

final TreeMap<String, Ref> avail = new TreeMap<>();

for (;;) {

String line = br.readLine();

if (line == null)

break;


final int tab = line.indexOf('\t');

if (tab < 0)

throw invalidAdvertisement(line);




git 저장소 대신 로컬 파일 시스템에서 테스트하려면 spring.cloud.config.enabled=false을 사용한다. 




Posted by '김용환'
,