[MSA] User-service에 Config 연동

jineey·2024년 11월 21일

MSA

목록 보기
21/36

Config

📌 개요

User-service에 Config 파일 설정 정보 연동

📌 소스코드

user-service

  • application.yml 수정
#token:
#  expiration_time: 86400000 #하루
#  secret: make_my_secret_user_token #임의

spring:
  cloud:
    config:
      name: ecommerce
  config:
    import: configserver:http://127.0.0.1:8888

user-service의 설정이 아닌 config-service의 설정 파일을 사용할 것이기 때문에 주석 처리

  • pom.xml 수정
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
  • bootstrap.yml 추가
spring:
  cloud:
    config:
      uri: http://127.0.0.1:8888
      name: ecommerce

bootstrap.yml
application.yml 파일보다 우선 순위가 높은 설정 파일

  • Controller.java 수정
//테스트용 내용 수정
@GetMapping("/health_check")
    public String status(){
        return String.format("It's Working in User Service"
                    + ", port(local.server.port)= "+env.getProperty("local.server.port")
                    + ", port(server.port)= "+env.getProperty("server.port")
                    + ", token secret = "+env.getProperty("token.secret")
                    + ", token expiration = "+env.getProperty("token.expiration_time"));
    }

📌 실행결과

  • 적용 확인

  • 값 변경 확인


    ➡ 현재는 user-service를 재기동하여 config 설정 정보를 적용함

profile
새싹 개발자

0개의 댓글