개발환경과 운영환경이 다르며 이에 따른
설정 정보 또한 다르다. SpringBoot 를 사용한다면YML, 이나properties에 설정 정보를 기록한다. 설정 정보가 변경 될 때마다
빌드된 파일들을 올리자니 너무 번거로운 일이다.
Spring Cloud Config 를 사용하면 조금 더 자유로운 설정 정보 변경을 할 수 있다. 기본적으로 설정 정보 저장을 위해 git을 사용하기 때문에
git 이 반드시 초기화 되어 있어야한다.
play-ground:
local-test: test
외부에서 사용할 yml 파일을 생성한다.
해당 파일은 GIT 이 반드시 초기화 되어 있어야한다.
그렇지 않으면 다음 예외가 추후에 발생 할 것이다.java.lang.IllegalStateException: No .git at file://c:\Users\SIUK\GIT_REPO\STUDY\JAVA\DowonLEE\SpringCloudMSA\study\section7 at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-6.1.3.jar:6.1.3] at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.copyFromLocalRepository(JGitEnvironmentRepository.java:646) ~[spring-cloud-config-server-4.1.0.jar:4.1.0]
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.0")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
server:
port: 8897
spring:
application:
name: config
cloud:
config:
server:
git:
uri: file://c:\Users\SIUK\GIT_REPO\SPRING_CONFIG\
위에서 설정한 YML 파일의 디렉토리 위치를 uri 로 지정한다.
@EnableConfigServer 어노테이션을 추가해준다.
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}

설정한 파일이름 ( play-ground ) 이름으로 파일에서 설정한 값을
볼 수 있다.