본문 바로가기

MSA

Spring Cloud Config 서버를 활용한 DB 정보관리

1. config-server 

application.java

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

}

application.yml 파일 

server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: file://C:\DevSoo\MSABackend\config-resource

 

2. config-resoure 폴더 내 test-db.yml 파일

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/msa_db
    username: 사용자명
    password: 비밀번호
    dirver-class-name: com.mysql.cj.jdbc.Driver  # .cj.이 붙는 것은 5버전 이상으로 cj 미작성 시 호환은 되지만, 지원하지는 않습니다.

 

3. config-client 

bootstrap.yml 파일

spring:
  cloud:
    config:
      uri: http://127.0.0.1:8888
      name: test-db

 

build.gradle 설정

dependencies {
	// spring-cloud-starter-config
    implementation 'org.springframework.cloud:spring-cloud-starter-config:4.0.4'

    // spring-cloud-starter-bootstrap
    implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.0.4'
}

 

4. 결과

인텔리제이를 통해 bootsarap.yml 파일에서 설정한
test-db.yml 파일로 정보가 들어오는 것을 볼 수 있습니다.

 

 

 

 

차후 Kohl's Admin Infinity (콜스 어드) 설정하기를 통해 보완을 유지하면서 config서버를 활용할 수 있습니다..