개발이 좋아서
cors 에러 문제 - trim을 안했다..
cors 에러 문제가 자꾸 나서 원인을 파악하려 했지만 찾기가 힘들었다.이미 하라는 것은 다했기 때문에 뭐가 문제인지 몰랐다. 하지만 원인은 너무도 쉬운 것이었다.원래 쉬운 것을 찾는게 더 어려운 것 같다.... app: cors: allowedOrigins: http://localhost:8080, http://localhost:8081, http://localhost:3000 이런식으로 허용해주고 있었는데 private List parseAllowedOrigins() { return Arrays.asList(allowedOrigins.split(","));}- 여기가 문제였다. 콤마하고 띄워쓰기가 있어서 제대로 적용이 되지 않았던 것이다...ㅠㅠㅠ private List parseAllo..
빈 등록 안하고 싶을 때 - @Autowired(required = false)
빈 등록이 필수가 아닌데 final로 빈을 등록하고 있었다!!그래서 @Autowired(required = false)를 주었다. 이후 null 체크를 하여 코드를 진행하였다.@Autowired(required = false)private SlackNotifier slackNotifier;if(slackNotifier != null) { // Slack으로 에러 알림 전송 slackNotifier.sendErrorNotification( "서버 에러 발생 (500 Internal Server Error)", e.getMessage() != null ? e.getMessage() : "알 수 없는 서버 에러가 발생했습니다.", e );}
@WithCustomMockUser - 테스트 코드 작성 시 인증
컨트롤러단에서 @AuthenticationPrincipal을 이용해 id값을 가져와 쓰고 있었다.테스트 코드를 작성하는데 id값을 어떻게 가져와야 할 지 몰랐다. 그래서 @WithCustomMockUser 어노테이션을 만들어 사용하였다.package com.swyp.libri.domain.annotation;import org.springframework.security.test.context.support.WithSecurityContext;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.RUNTIME)@WithSecurityContext(factory = ..
There were failing tests. See the report at: file:///C:/repository/ 프로젝트/build/reports/tests/test/index.html
사이드 프로젝트를 하는 도중 Swagger와 restDocs를 같이 쓸 수 있다하여 우선 빌드를 했다.그런데 There were failing tests. See the report at: file:///C:/repository/ 프로젝트/build/reports/tests/test/index.html이런 에러가 뜨는 것이다.에러 경로를 따라가 파악해보니 테스트 코드는@ActiveProfiles("test")이것으로 테스트 환경에서 돌리는 것이었다. 그래서 application-test.yml에 jwt와 Oauth와 같은 설정 정보를 넣어줘서 apllication-local.yml 파일과 맞추어 줘야 한다는 것을 알았다.

AWS ElasticCache 활용하기
현업에서 EC2에 Redis를 설치해서 쓰지않고 ElastiCache를 쓰는 이유현업에서 EC2에 Redis를 직접 설치해서 사용하는 경우는 드물다. 일일이 Redis를 설치하고 셋팅하고 관리하면서 확장까지 하려면 신경쓸 게 생각보다 많다. 하지만 ElastiCache를 사용하면 셋팅도 쉽게할 수 있고, 확장도 쉽게 할 수 있고, 기본적인 모니터링 기능도 제공해주고, 장애가 날 가능성도 훨씬 적다. 이런 이유로 인해 현업에서는 ElasitiCache를 많이 활용한다. AWS ElastiCache 셋팅하기1. ElastiCache 서비스로 들어가기2. 캐시 생성을 위해 ‘지금 시작’ 버튼 누르기 3. 클러스터 설정에서 ‘구성’ 선택하기- 여기서 얘기하는 클러스터(cluster)란 여러 캐시 서버를 이루는..
Docker Compose로 Redis + Spring Boot 띄우기
1. Dockerfile 만들기FROM openjdk:17-jdkCOPY build/libs/*SNAPSHOT.jar app.jarENTRYPOINT ["java", "-jar", "/app.jar"] 2. compose.yml 만들기services: api-server: build: . ports: - 8080:8080 depends_on: cache-server: condition: service_healthy cache-server: image: redis ports: - 6379:6379 healthcheck: test: [ "CMD", "redis-cli", "ping" ] interval: 5s ..
부하 테스트를 통해 Redis 적용 전 후 성능 비교하기
부하 테스트에서 서비스가 1초당 처리할 수 있는 작업량을 보고 Throughput이라고 부른다. 단위는 TPS(Transaction Per Seconds, 1초당 처리한 트랜잭션의 수)이다. 부하 테스트를 위한 환경 세팅 (k6)k6란?부하테스트 툴에는 k6 이외에도 ngrinder, jmeter, ab, locust 등 다양한 툴이 있다. 하지만 그 중에서 간단하고 빠르게 테스트 해볼 수 있는 툴인 k6를 활용하고자 한다. (실무에서도 많이 쓰임) k6는 사용자인척 요청을 보내는 툴이다.1. k6 설치하기2. 터미널 창에서 잘 설치됐는 지 확인$ k6 3. API에 부하를 주기 위해 k6 스크립트 작성script.jsimport http from 'k6/http';import { sleep } from..
AWS EC2에서 Redis 활용하기
EC2 생성성능 때문에 t3.a.small 이상으로 생성할 것을 권장보안 그룹 설정에서 8080번 포트 열어줄 것RDS 생성보안 그룹 설정에서 3306번 포트 열러줄 것EC2에 Redis 설치1. Redis 설치하기$ sudo apt update$ sudo apt install redis 2. 잘 설치됐는 지 확인$ redis-cli127.0.0.1:6379> pingPONG EC2에 Spring Boot 프로젝트 세팅1. JDK 설치하기$ sudo apt install openjdk-17-jdk 2. 잘 설치 됐는 지 확인$ java -version 3. application.yml 수정# local 환경spring: profiles: default: local datasource: ur..
로컬 환경에서 Spring Boot + Redis로 구현하기
기본 Spring Boot 프로젝트 세팅Spring Boot는 3.xx 버전MySQL 8.x 버전JDK 17application.yml# local 환경spring: profiles: default: local datasource: url: jdbc:mysql://localhost:3306/mydb username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true Board 엔티티 만들기@Entity@Table(name = "boards")public class Board { @Id @Gene..
Redis 캐싱 전략
캐시(Cache)란?캐시(Cache)란, 원본 저장소보다 빠르게 가져올 수 있는 임시 데이터 저장소를 의미한다. 캐싱(Caching)이란?캐싱(Caching)이란 캐시(Cache, 임시 데이터 저장소)에 접근해서 데이터를 빠르게 가져오는 방식을 의미한다. 데이터를 캐싱할 때 사용하는 전략(Cache Aside, Write Around)Cache Aside(= Look Aside, Lazy Loading)데이터를 조회할 때 주로 사용하는 전략이다.캐시에 데이터가 있을 경우 (= Cache Hit) : 데이터를 요청했을 때 캐시에 데이터가 있는 경우를 보고 Cache Hit라고 한다.캐시에 데이터가 없을 경우 (= Cache Miss) : 데이터를 요청했을 때 캐시에 데이터가 없는 경우를 보고 Cache M..