본문 바로가기

Back-End/SpringBoot

(14)
[SpringBoot/WebClient] WebClient ClientResponse로 성공/실패 응답 객체 각각 받기 토스 결제 API 연동 중 성공 시 응답 { "mId": "tosspayments", "version": "2022-06-08", "paymentKey": "T1UwdsBoNhvzO-fUy8BkC", "status": "DONE", "transactionKey": "-93-dcZeXmDd_pUfnKIwA", "lastTransactionKey": "MSmTdHS56DmjArbD2PeDM", "orderId": "xwFi1a_v3pidotzeXqkiE", "orderName": "토스 티셔츠 외 2건", "requestedAt": "2022-06-08T15:40:09+09:00", "approvedAt": "2022-06-08T15:40:49+09:00", "useEscrow": false, "cultur..
[SpringBoot/MapStruct] MapStruct source 없이 default value 넣기 target 지정 후 source가 null인 경우 default value를 넣어주는 defaultValue 속성과 달리, source를 주지 않고 default value를 주고 싶을 때 constant 속성 사용 enum 타입도 가능한 것으로 확인 @Mapping(target = "subscribeYn", constant = "Y") @Mapping(target = "isTrue", constant = "true") ResponseDTO toResponse(Entity entity); 참조 https://stackoverflow.com/questions/59484557/how-to-specify-a-default-value-for-a-boolean-field-using-mapstruct How to..
[SpringBoot] 슬랙 메시지 전송 사용이유 서비스 운영자를 위한 목적으로 특정 결과를 슬랙 전송 슬랙에 Incoming WebHooks 앱 추가 추가하면 채널을 선택(또는 추가)하고 웹훅 url을 복사 슬랙 전송 서비스 코드 작성 @Service public class SendMatchingFailSlack { private static final String WEB_HOOK_URL ="https://hooks.slack.com/services/~~~"; private final WebClient webClient; public SendMatchingFailSlack(WebClient webClient) { this.webClient = webClient; } public void send(MessageDTO messageDTO) { M..
[SpringBoot/JPA] @Embeddable, @EmbeddedId로 복합키 설정 복합키 설정 방법 1. @Embeddable 2. @IdClass 이렇게 두가지가 있는데 1번 사용 @Embeddable 어노테이션 추가한 Id 클래스 생성 @NoArgsConstructor @AllArgsConstructor @Embeddable public class MemberId implements Serializable { @Column(name = "MB_NAME") private String name; @Column(name = "MB_BIRTHDAY") private String birthday; } Serializable 인터페이스를 구현한 클래스를 생성 @EmbeddedId로 엔티티에 추가 @Getter @Entity public class Member { @EmbeddedId priv..
[SpringBoot] JPA org.hibernate.LazyInitializationException: could not initialize proxy JPA org.hibernate.LazyInitializationException: could not initialize proxy 발생원인 FetchType.LAZY로 맵핑된 객체를 조회할 때 해결방법 구글링 하면 FetchType.EAGER로 바꾸라는 방법도 나오지만, @Transactional(readOnly = true) 객체 조회하는 클래스(서비스 클래스) 에 위 어노테이션을 추가해서 해결
[SpringBoot] 잘 되던 인터셉터가 동작이 안 될 때, 인터셉터 등록 방법 변경 로컬에서는 잘 작동하던 인터셉터가 배포 후에는 작동이 안 되는 게 확인되었습니다. 인터셉터 등록 조차 되지 않아서 인터셉터 등록 방식을 변경했습니다. 원인은 모르겠습니다.. 기존 인터셉터 등록 방식 @Configuration public class CustomWebConfig extends WebMvcConfigurationSupport { @Override protected void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new UserHandlerInterceptor()); } } 변경 후 @Configuration public class CustomWebConfig { @Bean public MappedInte..