본문 바로가기

Spring Boot28

[Spring] IntelliJ RMI TCP Connection 에러 상단 Edit Configurations에서 Disable JMX agent 체크를 통해 해결할 수 있습니다. ref : https://stackoverflow.com/questions/47283504/rmi-tcp-connection-error-when-starting-spring-boot-application 2023. 3. 14.
[Spring] 유니크 키 제약사항을 위반한 경우 HTTP 상태 코드 회원가입 시나리오로 예를들면 사용자가 입력한 아이디를 '아이디 중복확인' 버튼을 통해 중복체크 API 호출 이때 아이디가 중복된 상태라면 Response로 어떠한 상태 코드를 반환해야 할까? 기존에는 409 Conflict(원본과 현재 요청이 충돌)를 사용했지만 422 Unprocessable Entity(요청은 정확하게 이루어졌지만 처리할 수 없음)가 더 적절한 상태코드인것 같다. 출처 : https://stackoverflow.com/questions/25015592/whats-the-best-return-code-for-unique-violations What's the best return code for "@unique" violations? I'm working on a RESTful web .. 2023. 2. 1.
[Spring] 2개 이상의 유니크 키를 분리하여 예외처리 하기 @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "UC_email", columnNames = { "email" } ), @UniqueConstraint(name = "UC_username", columnNames = { "userName" } ) }) public User myFancyServiceMethod(...) { try { // do your stuff here return userRepository.save( user ); } catch( ConstraintViolationException e ) { if ( isExceptionUniqueConstraintFor( "UC_email" ) ) { throw new EmailAddr.. 2023. 1. 31.
[Spring] @Transactional 롤백 기능 이용하기 @Transactional(rollbackFor = XYZException.class) 괄호 안에 롤백을 수행할 익셉션을 명시해주면 된다. ref : https://stackoverflow.com/questions/62887614/how-to-do-rollback-with-transactional-annotation 2023. 1. 18.