Spring 5

[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

[Intellij] Spring 프로젝트 빌드 후, jar 실행시 ClassNotFoundException 발생 오류 해결

로컬 환경에서는 문제가 없었는데 빌드후 Executable jar을 실행하니 클래스 하나를 로드하지 못하였다. jar에 해당 라이브러리만 추가가 안 된듯 싶었다. 구글링 해 보니 다음과 같은 방법으로 추가 가능 이후 실행이 잘 되었다. Intellij를 처음써서 생기는 어이없는 오류 출처 https://youn12.tistory.com/42

개발/Intellij 2022.05.25