목록JAVA (41)
정구리의 우주정복

redis 연결하고 데이터 넣기 ? 어렵지 않다 우하하연결하고 -> redisTemplate 작성하고 -> 내용 뿍 넣으면 된다연결하기일단 local 에 redis 하나 띄워주겠다 (이미 떠있는거 있으면 그거 쓰삼 !!!)docker run -d --name redis-local -p 6379:6379 redis:latest그리고 프로젝트에 설치한걸 연결해주자build.gradleimplementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'나는 r2dbc 사용중이라 reactive 를 해줬다 만약 jdbc 라면 spring-boot-starter-data-redis 를 쓰세용application.ymlspring: da..
Spring mvc 사용할땐 @Transactional 을 사용하면 모든게 다 해결 되었지만 .. WebFlux 를 사용하면 그렇지 않다 슬프다 ! 그럼 어떻게 해야할까 바로바로 TransactionalOperator 를 사용해야한다 ! 일단 build.gradle 에 해당 내용을 추가해준다 특이하게 aop 를 추가해야함 implementation 'org.springframework.boot:spring-boot-starter-aop:3.4.5'implementation 'org.springframework.boot:spring-boot-starter-webflux' 그리고 ReactiveTransactionManager 를 설정해줘야함 !!!package com.example.toygry.webflu..
비동기 처리할때 사용하는 WebFlux 에 대해서 정리해보려 한다 ! 써봤는데 남들에게 설명해줄 수준은 아니라 .. 정리해보기 전통적인 Spring MVC와의 차이종류SpringWebFlux프로그래밍 방식동기 (블로킹)비동기 (논블로킹)기반 APIServlet APIReactive Streams (Project Reactor)스레드 사용요청당 스레드 하나적은 수의 스레드로 수많은 요청 처리Return 타입String, Model, ResponseEntityMono, Flux 기존에도 자바에는 Thread 나 Virtual Thread 와 같은 비동기 처리들이 있는데 이들과는 어떤 차이가 있는지 알아보장 내가 이해한 바로는 WebFlux는 프로젝트 전체가 비동기로 돌아가는 거고,Thread나 Virtual..
프로젝트를 하다보면 Response 가 제각각이라 이녀석이 성공인지 실패인지 어떤 상태인지 표현하기가 어렵다그래서 오늘은 공통 Response 를 정의해서 Http status 값과 ,message 그리고 Data 를 넣어보려 한다 어렵지 않음 !!!"기존 Response 를 한번 더 감싸준다"라고 생각하면 쉽다 data class BaseResponse( val status: HttpStatus, val message: String, val data: T? = null) 나는 status , message, data 를 넣었지만 자기한테 필요한 형태로 커스텀 해서 사용 가능하다 만약 기존에 ResponseEntity 이렇게 사용했다면 ResponseEntity> 이렇게 정의해주면 된..

거지같은 메일 전송 (1) 구글 설정Gmail 로 이동 모든 설정보기 클릭 !!! 이거 설정 켜기 (2) 구글 2단계 인증 켜기 보안 > 2단계 인증 들어가서 켜기 !!! 다시 와서 구글 앱 비밀번호 검색 후 만들기 만들어진 앱 비번 복사 고고고 !!!!!!!! (3) Kotlin 으로 돌아와서 spring: mail: host: smtp.gmail.com port: 587 username: 구글 이멤일 password: 앱비밀번호 properties: mail: smtp: auth: true timeout: 5000 starttls: enable: true application.y..
코드를 쓰다보면 val routine = routineRepository.findById(routineId).orElseThrow{ IllegalArgumentException("routine not found") } 이렇게 작성한 경우에는 routine 의 값을 가져올때 (isSuccess) routine.isSuccess 이렇게 가져오고 val routine = routineRepository.findById(routineId) 요롷게 하면 routine.get().isSuccess 이렇게 가져와야한다 왤까 바로바로 타입의 차이이다 orElseThrow 를 사용하게 되면 값이 존재하면 객체 (Routine) 를 반환하고 없으면 예외를 발생하기 때문에 무조건 객체를 가지고 있다고 생각하기 때문에rout..
@Transactional override fun deleteRoutine(userId:Long, routineId: Long): Long { // routine entity 가져와서 val deleteRoutine = routineRepository.findById(routineId).orElseThrow {IllegalArgumentException("routine not found")} // 유저 유효한지 확인하고 val loginUser = userRepository.findById(userId).orElseThrow {IllegalArgumentException("user not found")} if (deleteRoutine...

나도 멋진 CI/CD 를 갖고싶다 Git Action 을 사용해서 만들어봐야징 서버는 Synology 사용했다git action 작성하는거는 어렵지 않았는데 서버 설정이 굉장히 어려웠음 .. 폴더는 .github > workflows > deploy.yml 생성하면 된덩 name: CI/CD for Synologyon: pull_request: branches: - main types: - closedjobs: build: if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@..