본문 바로가기

Spring5

[Spring] Spring Boot 3를 위한 RestDocs, openAPI3 버전 업그레이드 스프링부트 버전 2.x 에 restdocs + openapi3 를 이용하여 요청, 응답값을 테스트한 뒤 문서화를 위한 제너레이션을 하고 있었습니다. 문서 테스트 코드는 동일하게 두고 테스트를 돌리면 위와 같이 java.lang.NoClassDefFoundError: org/springframework/restdocs/operation/QueryStringParser 에러가 발생하였습니다. spring boot 버전업을 했으니 문서화 관련 의존성의 버전들도 짚어볼 필요가 있어보입니다. 스프링부트 3 버전부터는 스프링 프레임워크 6을 사용합니다. spring-restdocs 3.0.0 버전의 dependecy 정보를 보면 스프링 프레임워크의 의존성이 6으로 올라간 것을 확인할 수 있습니다. 따라서, org... 2023. 3. 30.
[Spring] Spring Cloud Config 정리 개요 MSA 아키텍처에서는 환경설정 파일을 외부에서 관리하여 설정이 바뀐 경우 서비스의 수정, 재컴파일 없이 여러 환경에서 이를 적용할 수 있게 해줍니다. 이를 위해 Spring 프레임워크는 Spring Cloud Config를 제공합니다. 기본 세팅 컨피그 서버를 사용하는 경우 구조는 [그림 1]과 같습니다. 컨피그 파일 repository가 존재하며 컨피그 서버는 뜰 때 해당 레포를 바라봅니다. 서비스들은 배포될 때 컨피그 서버에서 배포 시 환경의 환경설정 정보를 가져와서 서버를 띄워줍니다. spring boot actuator 의 refresh endpoint를 이용하여 config file의 변경점이 있다면 서버 재시작을 하지 않고도 미리 명시해둔(@RefreshScope) 컨피그들은 변경된 정보.. 2022. 5. 15.
[Spring][Kotlin] Main class name has not been configured and it could not be resolved Execution failed for task ':bootRun'. > Failed to calculate the value of task ':bootRun' property 'mainClass'. > Main class name has not been configured and it could not be resolved 어플리케이션 띄울때, main class를 못찾는다고 한다. // build.gradle.kts springBoot { mainClass.set("com.withhamit.chatting.ChattingApplicationKt") } mainClass 위치를 명시적으로 지정해준다. 코틀린으로 작성한 경우 자바로 컴파일될때 파일명에 Kt가 붙기 때문에 ChattingApplication.. 2021. 6. 26.
[SPRING] Controller redirect @GetMapping("main") public String main() { if(특정조건){ "redirect:fail"; // '/fail' path로 리다이렉트 } return "main"; } 특정조건인 경우 특정 path로 redirect 하게 해준다. @GetMapping("main") public String main() { if(특정조건) { return "fail"; // fail.jsp 반환 } return "main"; } 특정조건인 경우 특정 페이지를 내려준다. (이 경우는 리다이렉트가 아님) 2019. 5. 30.
[spring] webClient error 처리 기존코드 WebClient.create().get() .uri("http://~~~") .retrieve() .bodyToMono(CustomResponse::class.java) .onErrorMap { e -> log.error(e.message) e // return e } .map { // return } CustomResponse 타입의 body를 가져와서 처리한다. 에러가 발생하는 경우(4xx, 5xx) onErrorMap이 에러를 캐치해서 log.error로 해당에러를 찍는다. WebClient.create().get() .uri("http://~~~~") .exchange() .flatMap { response -> // get header val header = response.heade.. 2019. 5. 8.