본문 바로가기

트러블 슈팅

kotlin + Jpa Lazy Loading 트러블 슈팅 상황 1 Kotlin과 JPA를 사용하면서, 다음과 같은 plugins를 적용하고 LazyLoading을 사용하였으나, 적용되지 않는 문제가 발생하였다. kotlin("plugin.spring") version "1.8.21" kotlin("plugin.jpa") version "1.8.21" 🔎 plugin.spring: 다음과 같은 어노테이션이 붙은 코틀린 클래스에 대해 자동으로 붙는 final 키워드를 open 해주는 allOpen을 지원한다. Spring boot 2.x 버전부터 CGLIB Proxy 방식으로 Bean을 관리하고 있어, Target Class를 상속받아 프록시를 생성하기 때문에 open으로 열기 위해 사용한다. @Component, @Async, @Transactional, @Ca.. 더보기
클라이언트-서버 cookie 사용 문제 상황 Jwt 웹 토큰을 사용하면서, RefreshToken은 보안 상의 문제로 Cookie를 통해 프론트 서버로 전송하려고 상황에서 프론트에서 cookie를 사용하지 못하는 에러 상황이 발생했다. ❗ 초기 Cors 설정 registry .addMapping("/api/**") .allowedOriginPatterns("*") .allowedMethods("*") .allowedHeaders("*") .allowCredentials(true); Set-Cookie ResponseCookie refreshTokenCookie = ResponseCookie.from(REFRESH_TOKEN_HEADER, refreshToken) .httpOnly(true) .maxAge(refreshExpiredTimeMs).. 더보기
Jpa Validate 에러 (with. Oracle DB, h2) 프로젝트를 진행하며, Local, Dev, Prod 환경에서는 Oracle Database를 사용하고, Test 환경에서는 H2 데이터 베이스를 사용했다. ✔ Entity @Entity @Table(name = "users") @SequenceGenerator(name = "USERS_SEQ_GENERATOR", sequenceName = "USERS_SEQ", initialValue = 1, allocationSize = 1) class User( @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USERS_SEQ_GENERATOR") val id: Long = 0L, @Column(nullable = false, updatabl.. 더보기
Kotest + 생성자 Bean 주입 상황 @WebMvcTest(TestController::class) class TestControllerTest @Autowired constructor( private val testService: TestService ) : DescribeSpec({ describe("---") { context("---") { it("---") { --- } } } }) Kotest DCI 패턴을 적용하여 테스트를 진행하려고 테스트 코드를 작성하는 과정에서 생성자를 통해 빈을 주입 받으니 다음과 같은 에러가 발생했다. io.kotest.engine.spec.SpecInstantiationException: Could not create instance of class kr.weit.odya.controller.te.. 더보기
Kotlin + Spring DTO에서 NotNull 변수의 null Validation 📒 상황 data class FacilityReq( @NotNull val category: Category, @NotBlank val name: String ) ◼ 시설 등록 요청 DTO를 위와 같이 작성하고 name 값을 넣지 않고 요청을 보내면 에러가 발생한다. 💥 기대했던 에러는 name은 null이 될 수 없다는 에러였는데, 에러 API 응답으로 설정한 값과 다른 값이 응답으로 왔다. 📒 원인 name을 NotNull 타입인 String으로 설정해서 null을 허용하지 않는 타입으로 정의했다. 이로 인해, name이 null로 채워지게 된다면 @field:NotBlank validation 로직을 타기 전에 변수에 값을 할당하는 과정에서 예외가 발생하게 되어 다음과 같은 에러가 발생한다. 💥 H.. 더보기
[Junit5] JPA metamodel must not be empty! Spring-Boot 환경에서 Junit5를 사용한 Controller 단위 테스트를 진행하는 도중, 다음과 같은 에러가 발생하였다. Caused by: java.lang.IllegalArgumentException: JPA metamodel must not be empty! Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: JPA metamodel must not be empty! 원.. 더보기
[Junit5] org.mockito.exceptions.misusing.MissingMethodInvocationException AuthService 단위 테스트를 작성하던 도중 JwtTokenUtils 내부의 static method를 mocking하고 테스트를 진행하니 다음과 같은 에러가 발생하였다. org.mockito.excptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles); Also, this error might show up because: 1. you stub either of: final/private/equals()/hashCode() method.. 더보기
[Spring] Spring Security + Junit5 환경: Spring Boot version '2.7.5.' + spring webflux + spring security 상황 Security 설정을 다음과 같이 작성하였다. @Configuration @EnableWebFluxSecurity public class SecurityConfig { @Bean SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { http .csrf().disable() .authorizeExchange( authorize -> authorize.pathMatchers("/api/v1/members/join").permitAll() .anyExchange().authenticated() ) .form.. 더보기