전체 글 39

[Spring Boot] Spring cache 를 사용해 보자

Introduction 최근 데이터 게시판 조회수 에 관련하여 최적화 방법을 찾아보던 중 Spring 에도 내장된 캐싱 방법이 있다는 것을 발견하고 알아보기로 하였다. 해당 문서에서는 spring--boot-starter-cache 라이브러리에 대한 간단한 설명 및 실습을 진행한다. Dependencies implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-cache' Conception Spring Cac..

개발/Spring Boot 2024.02.07

[Spring Boot] Spring Boot Application 을 재시작해도 Spring cache가 초기화 되지 않는 문제 해결

Introduction Spring-boot-starter-cache 라이브러리를 사용하던 중 Spring Application 을 재시작해도 캐시가 초기화 되지 않아 빈 DB를 조회해도 Cache 에서 데이터를 꺼내 반환하는 문제가 발생하였다. 심지어 Intellij 를 껏다 켜도 마찬가지였다. 컴퓨터를 재부팅 해야지만 캐시가 초기화 되었다. 상식적으로 Spring cache는 Spring Application 내부의 메모리를 사용하는 것일텐데 어떻게 App 이 종료되어도 캐시가 초기화되지 않는 것인가? Code Controller @GetMapping("/{postId}") public ResponseEntity getPost(@PathVariable long postId) { return Respo..

개발/Spring Boot 2024.02.07

[ModelMapper] 필드 타입이 다른 두 객체간 매핑 커스텀하기

Introduction 프로젝트를 진행하던 중 타입이 다른 두 객체간에 ModelMapper로 매핑을 할 일이 생겼다. public class Person { ... private String images; } public class PersonDto { ... private List images; }Entity의 Images는 String 타입으로 여러 이미지 파일 이름을 ;를 구분자로 사용하여 저장하고, Dto는 String 을 Split 하여 리스트로 변환하여 응답해야 하는 상황이다. 즉, "a;b;c;d" -> ["a", "b", "c", "d"]위와 같이 매핑하는것이 목표이다. Solution ExpressionMap과 Converter를 사용하면 된다. ExpressionMap은 람다 식을 이..

개발/Spring Boot 2023.12.02

[VPC] VPC 피어링을 사용하여 EC2 인스턴스간 Private IP로 통신하기

Introduction MSA 구조에서의 마이크로 서비스들은 보통 외부로 노출되지 않고 게이트웨이를 통하여 통신을 한다. 하지만 현재 필자의 마이크로 서비스들은 모두 EC2의 탄력적 IP를 할당받아 외부에서 접근 가능한 상태이다. 때문에 이를 수정하고자 하였다. 이 포스팅에서는 서로 다른 AWS 계정의 EC2 인스턴스들이 상호 간에 Private Ip로 통신할 수 있도록 설정하는 방법을 설명한다. VPC Peering 동일한 AWS 계정의 VPC 간 연결이나 서로 다른 AWS 계정의 VPC간 연결 모두 VPC Peering을 통하여 연결이 가능하다. 피어링을 통해 연결 후, 라우팅 테이블을 설정해 주기만 하면 사설망으로 상호 VPC간의 통신이 가능하게 된다. 하지만 주의할 점은 VPC Peering 통신..

개발/AWS 2023.12.01

[EC2] AMI 를 이용하여 EC2 인스턴스를 복사해 보자

Introduction EC2 인스턴스를 사용 중에 VPC를 교체할 일이 생겼다. 하지만 불행하게도, EC2 인스턴스는 한 번 생성되면 VPC, Subnet, 가용영역 등을 바꾸는 것이 불가능하다. 따라서 새로운 EC2 인스턴스를 생성하고 볼륨을 교체하려고 했다. 하지만 AMI 를 생성하고 인스턴스를 복사해 버리는 것이 편하다는 것을 알게 되었다. 해당 포스팅은 실행중인 EC2 인스턴스의 AMI를 생성하고, 해당 이미지를 토대로 인스턴스를 복제하는 방법을 알아본다. 루트 볼륨 대체 만약 볼륨대체를 하고 싶다면 이 방법을 사용하면 된다. 하지만 필자와 같은 경우라면 이 방법은 사용하지 않는게 더 편리하므로 넘기면 된다. AWS는 OS가 설치된 루트 볼륨 교체를 위한 솔루션을 제공한다. 이를 이용하면 인스턴..

개발/AWS 2023.11.30

[4주차] 133. Clone Graph

https://leetcode.com/problems/clone-graph/?envType=study-plan-v2&envId=top-interview-150 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📝 문제 무방향 그래프의 노드 하나가 주어진다. 해당 그래프를 깊은 복사를 수행 후, 새로운 그래프를 리턴하시오. 🎈 풀이 쉽게 풀 줄 알았는데 생각보다 ..

[3주차] 208. Implement Trie (Prefix Tree)

https://leetcode.com/problems/implement-trie-prefix-tree/description/?envType=study-plan-v2&envId=top-interview-150 Implement Trie (Prefix Tree) - LeetCode Can you solve this real interview question? Implement Trie (Prefix Tree) - A trie [https://en.wikipedia.org/wiki/Trie] (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of s..

[3주차] 637. Average of Levels in Binary Tree

https://leetcode.com/problems/average-of-levels-in-binary-tree/?envType=study-plan-v2&envId=top-interview-150 Average of Levels in Binary Tree - LeetCode Can you solve this real interview question? Average of Levels in Binary Tree - Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accept..

[3주차] 199. Binary Tree Right Side View

https://leetcode.com/problems/binary-tree-right-side-view/description/?envType=study-plan-v2&envId=top-interview-150 Binary Tree Right Side View - LeetCode Can you solve this real interview question? Binary Tree Right Side View - Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: [h..