HTTP 통신
Rest API
넷플릭스에서 만든 통신 라이브러리?
설정 법
공식 문서 https://spring.io/projects/spring-cloud
Spring Cloud
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, short lived microservices and
spring.io
Spring boot 버전에 맞는 의존성 주입
우리 프로젝트는 3.4 버전을 사용하기 때문에 하위 의존성을 추가
ext {
set('springCloudVersion', "2024.0.1")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
//...
}
이후 Application 에 @EnableFeignClients 추가
spring:
config:
import: optional:configserver:http://localhost:8888 //불러올 api url
cloud:
config:
enabled: false //로컬환경이라 false
profiles:
include: office-data
eureka:
client:
enabled: false //로컬환경이라 false
api:
url: http://localhost:8080 //불러올 api url
server:
port: 8081 //현 서버포트(진행중인 프로젝트 두개의 모듈을 실행하기 때문에 포트 분리)
위와 같이 .yml 수정
AppClient + DTO 작성(사용할 api가 클라이언트가 되는 거라고 생각하면 될듯?)
이후 모듈에서 평시 CRUD를 만들듯 사용하면됨 대신 service에서 AppClient를 주입해서 사용 (레포지토리마냥)
'개발일기 > CS(면접)' 카테고리의 다른 글
아키텍쳐 종류 그리고 특징 (0) | 2025.02.24 |
---|---|
Comparator를 활용한 문자열 정렬: 오름차순, 내림차순, 길이순 정렬까지 (0) | 2025.02.02 |
브루트 포스 (Brute Force) 알고리즘이란? (0) | 2025.01.24 |
StringTokenizer 와 split과 차이점 (0) | 2024.12.26 |
Scanner 차이 BufferedReader (0) | 2024.12.18 |