본문 바로가기
반응형

Spring56

[Spring] Kotest에서 @Transactional을 사용하는 방법 이번 포스팅에선 Kotest로 작성된 테스트 코드에서 @Transactional을 사용하는 방법에 대해 알아보겠다. @Transactional을 선언해보자 아래 테스트 코드는 Kotest의 DescribeSpec으로 작성된 코드다. @Transactional을 붙여보겠다. @Transactional @SpringBootTest class UserRepositoryTest( private val userRepository: UserRepository ) : DescribeSpec({ describe("save") { context("User를 저장하면") { userRepository.save(User(name = "노력남자")) it("정상적으로 저장된다.") { userRepository.findAll.. 2023. 12. 10.
[Spring] Exceeded limit on max bytes to buffer : 262144 해결책 문제 WebClient로 api 호출하는데 간헐적으로 "org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144"가 발생했다. 참고, webflux나 netty를 사용 중이면 아래 에러가 추가로 발생한다. io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 에러 로그 - Error was received while reading the incoming data. The connection will be closed. io.netty.util.IllegalReferenceCountException: .. 2023. 12. 3.
[Spring] Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. 해결책 문제 새로운 Spring Boot 프로젝트를 만들고 실행하려고 보니 runApplication에 빨간 줄이 있어서 마우스를 올려보니 "Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option" 라고 나왔다. 원인 gradle에 Java 버전을 21로 다 세팅해놨다. 찾아보니 IntelliJ는 2023.3 버전부터 Java 21을 지원한다. 내 IntelliJ 버전을 확인해보니 2023.1.5다. 그렇다. 21을 지원하지 않아서 저렇게 세팅해놔도 내 프로젝트는 1.8버전으로 세팅이 된다. 아오. 해결책 1.. 2023. 11. 27.
[Spring] Some Kotlin runtime libraries has an unsupported binary format 해결책 문제 집에서 테스트할 땐 Spring, Kotlin 등 호환이 된다면 항상 최신 버전을 사용하고 있다. IntelliJ로 Spring Boot 프로젝트 만들고 신나게 코드 작성하려고 보니 갑자기 뜬금없이 "Some Kotlin runtime libraries has an unsupported binary format"이라는 에러가 상단에 나왔다. Downgrade all Kotlin runtime libraries를 클릭해봤더니 뭐지 이거... 무슨 프로젝트 만들기만 했는데 이런 해결도 안 되는 에러가 발생했지..? 원인 gradle 버전 호환이 안 되는 건가.. 뭐지 계속 찾다가 Kotlin 공식 홈페이지 접속해서 버전 별 소개 글 보다가 IDE support 보니까 kotlin 1.9.20은 2023.. 2023. 11. 26.
[Spring] jackson String "00": not one of the values accepted 에러 해결책 문제 Spring Boot 버전 업한 후 테스트를 돌리던 중 @JsonValue를 붙여놓은 enum으로 역직렬화되는 코드에서 "jackson String "00": not one of the values accepted" 에러가 발생했다. 아래 코드를 보며 자세히 알아보자. 역직렬화할 json은 아래와 같았다. userType은 문자열 타입이다. { "userType": "00" } 위 json을 역직렬화할 UserType의 code의 타입은 Int다. (enum에서 @JsonValue를 사용하면 직렬화, 역직렬화 둘 다에 사용된다.) class User( val userType: UserType ) { enum class UserType( @JsonValue val code: Int ) { NORMAL.. 2023. 11. 15.
[Spring] Non supported character set (add orai18n.jar in your classpath): KO16MSWIN949 에러 해결책 문제 Spring Boot에서 Oracle 연결해서 JPA로 쿼리를 실행한 순간 "Non supported character set (add orai18n.jar in your classpath): KO16MSWIN949" 에러가 발생했다. 원인 ojdbc 라이브러리에선 지원해주지 않는 character set이라서 그렇다. 해결책 에러에 나와있는 orai18n 라이브러리 의존성 추가를 해주면 된다. 구글링해보니 무슨 jar 파일을 어디에 넣으라고 하는데 굳이 그럴 필요가 없다 https://mvnrepository.com/artifact/com.oracle.ojdbc/orai18n/19.3.0.0 implementation("com.oracle.ojdbc:orai18n:19.3.0.0") 2023. 11. 14.
[Spring + Kotlin] class, enum에서 @JsonValue 사용하는 방법 이번 포스팅에선 Jackson의 @JsonValue 사용법에 대해 알아보겠다. 프로젝트에서 제일 많이 사용하는 jackson 어노테이션인데 아무 생각없이 쓰다가 문득 정리하고 싶어서 정리한다. @JsonValue란? @JsonValue는 직렬화할 때 사용하는 어노테이션으로 클래스의 프로퍼티, getter, 인자가 없는 메소드 에 사용할 수 있으며, 최대 1개만 사용이 가능하다. (2개 이상 사용하면 "Multiple 'as-value' properties defined" 에러가 발생한다.) 특이한 건 enum에 사용하면 직렬화, 역직렬화 둘 다에 사용된다. 단, @JsonCreator가 있는 경우 @JsonValue는 역직렬화에 사용되지 않는다. @JsonValue 사용법 Class + @JsonValu.. 2023. 11. 13.
[Spring + Kotlin] no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator 해결 방법 문제점 코틀린에서 jackon 라이브러리 이용해서 json deserialization 테스트하다가 정상적으로 잘 돼야 하는데 계속 "no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator" 라고 에러가 발생했다. 원인 jackson은 deserialization을 하려면 빈 생성자가 있어야 한다. 코틀린은 빈 생성자를 별도로 만들 수 없다. 해결책 1. jackson-module-kotlin 의존성을 추가해준다. https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson.. 2023. 11. 10.
[Spring + Kotlin] class, enum에 @JsonCreator 사용하는 방법 이번포스팅에선 jackson 라이브러리에서 제공하는 @JsonCreator를 사용하는 방법에 대해 알아보려고 한다. @JsonCreator란? json을 class로 바꿀 때 사용하는데 생성할 class의 기본 생성자를 사용하는 게 아니라 다른 생성자나 팩토리 함수를 통해서 class를 만들고 싶을 때 사용한다. @JsonCreator 사용법 class + @JsonCreator - 다른 생성자 constructor 위에 @JsonCreator를 붙이고 생성자 파라미터에 @JsonProperty("필드명")을 반드시 붙여줘야 한다. @JsonProperty를 붙이는 이유는 정확하게 모르겠지만 사용법에 붙이라고 나와있어서 붙였다. class Member( val id: Long, val name: Stri.. 2023. 11. 9.
반응형