Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- VI
- mysql 표
- 맥
- oh-my-zsh
- Less
- MySQL
- 오일러 경로
- 데이크스트라
- 인프런워밍업클럽
- spring boot
- 이진탐색
- 인프런
- 티스토리챌린지
- table status
- 스터디2기
- CS스터디
- mysql 표 출력
- zsh
- 욕심쟁이 방법
- 오블완
- cs
- 알고리즘
- 동적 프로그래밍 방법
- zsh theme
- mycli
- 터미널
- Pager
- 순차탐색
- 분할정복 방법
- 네트워킹데이
Archives
- Today
- Total
Develop
36일차_공공데이터 (Open API) + Spring Cloud (OpenFeign) 연동 실습 본문
백엔드/KDT_Programmers
36일차_공공데이터 (Open API) + Spring Cloud (OpenFeign) 연동 실습
230801 2025. 4. 29. 09:39안녕하세요
오늘은 데브코스 36일차(8주 2일차) 입니다.
서울시 공공데이터를 API 연동해서 Spring Cloud 실습을 진행했습니다.
1. 데이터 찾기
: 서울시 API 인증키 발급
- 공공데이터포털 (한국정부)
- 서울 열린데이터광장 (서울시)
2. Spring Cloud 시작
Spring Cloud 란 ?
마이크로서비스(MSA) 아키텍처를 쉽게 만들 수 있도록 도와주는 Spring 프로젝트 모음집.
(ex: 서비스 등록, API 호출, Config 서버 구축 등)
Spring Cloud Train Reference Documentation :: Spring Cloud Release
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). Coordination of distributed
docs.spring.io
Spring Cloud를 쓰는 이유
- RestTemplate 보다 코드가 간결함
- RestTemplate : 스프링에서 외부 HTTP 요청을 보내기 위해 사용하는 오래된 방식의 클라이언트(자바판 Postman 역할)
- 요청/응답 DTO 만 만들면 API 호출 가능
- 인터페이스 기반이라 테스트도 편함
OpenFeign이란?
HTTP 통신을 인터페이스만 만들면 끝나게 해주는 라이브러리
(복잡한 RestTemplate 코드 없이, 인터페이스 메서드만 짜면 API 호출 가능)
OpenFeign 을 이용해 외부 API 호출을 인터페이스 기반으로 구현
1. pom.xml dependencyManagement 추가
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2024.0.1</version> <!-- Spring Boot 버전에 맞게 조정 -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2. OpenFeign 의존성 추가
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
3. XML 파싱용 라이브러리 추가 (에러 대응용)
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.18.3</version>
</dependency>
- API 응답이 XML 형식이면, JSON처럼 쉽게 파싱하려고 추가
3. API 연동 준비
- Postman으로 api 연동 사전 테스트
- @EnableFeignClients → 메인 클래스에 추가 (Feign 인터페이스 스캔용)
- API 응답 데이터(JSON/XML)을 받아올 수 있도록 DTO 클래스 생성
- @JsonProperty("NODE_ID") 같은 어노테이션으로 JSON key 매핑
- XML 데이터도 처리할 수 있도록 Jackson XML Parser 추가
- 응답 받을 필드도 모두 세팅
4. Feign 메서드 작성
- 참고 링크: RequestTemplate 공식 문서
- 리퀘스트 만들 때, pom.xml (또는 build.gradle)에 필요한 의존성 추가 완료
5. MyBatis 작성시 주의사항
<if test="search == 'author'">
or author like concat('%', #{keyword}, '%')
</if>
- #{} 사용해야 SQL Injection 공격을 방어할 수 있음
6. 1차 프로젝트 시작
- 기존 팀과 어느정도 기획된 프로젝트를 일주일간 진행하게 됨 .ᐟ
- 구조 잡기 (패키지 설계, 기본 뼈대 세팅)
- 설계하기 (기능별 책임 나누기, API 흐름 잡기)
감사합니다.
'백엔드 > KDT_Programmers' 카테고리의 다른 글
| 41일차~54일차_2차 프로젝트 진행 (0) | 2025.05.23 |
|---|---|
| 37~40일차_1차 팀 프로젝트 진행 (상품 주문 관리 프로젝트) (0) | 2025.05.03 |
| 35일차_SpringBoot: QueryDSL 적용, Boilerplate 마이그레이션, Thymeleaf 전환 (0) | 2025.04.22 |
| 34일차_Spring-JPA(영속성 컨텍스트, Entity 연관관계 매핑, N+1문제, CRUD), Spring-data(JPA 설정 및 사용, QueryDSL 사용준비) (0) | 2025.04.21 |
| 33일차_Spring Boot, Thymeleaf, JPA, JPQL (0) | 2025.04.21 |