spring-boot
-
Spring Framework의 테스트 클래스에서 단일 생성자로 의존성 자동 주입이 되지 않는 이유Spring Boot 2024. 10. 9. 21:39
사전 지식Spring Framework 4.3부터 해당 빈(bean)의 생성자가 하나뿐인 경우, 그 생성자에 @Autowired를 붙이지 않아도 생성자 주입이 된다.원문As of Spring Framework 4.3, an @Autowired annotation on such a constructor is no longer necessary if the target bean defines only one constructor to begin with. However, if several constructors are available and there is no primary/default constructor, at least one of the constructors must be annotated ..
-
Spring Boot : ProblemDetailsExceptionHandlerSpring Boot 2024. 4. 10. 18:55
ProblemDetail ProblemDetail은 Spring Framework 6.0에 추가된 REST API의 에러 응답 표준이다. RFC 7807에 정의되어 있다. 참고: https://docs.spring.io/spring-framework/docs/6.0.7/reference/html/web.html#mvc-ann-rest-exceptions 아래는 간단히 Spring Boot의 기본 에러 응답을 ProblemDetail로 설정하는 방법을 설명한다. ProblemDetailsExceptionHandler 에러 응답 예시 아래는 Spring Boot의 기본 에러 응답을 ProblemDetail로 설정했을 때의 에러 응답 body이다. { "type": "about:blank", "title": ..
-
Spring Boot : Default Error Response : 기본 에러 응답Spring Boot 2024. 4. 10. 18:33
개발 환경Java 21Spring Boot 3.2.4기본 에러 응답Spring Boot에서 아무 설정도 하지 않고 RestController 구성하여 예외 발생시키면 다음과 같은 형태의 response body를 응답한다.{ "timestamp": "2024-04-05T13:37:51.440+00:00", "status": 405, "error": "Method Not Allowed", "path": "/"}어디에서 기본 에러 응답 body를 만드나?어디에서 어떤 과정을 거쳐 이런 형태의 에러 응답을 하는지 궁금하여 간략하게 정리해보았다.아래에 그 과정에서 알게된 몇 가지 설정도 적어두었다.아래에서 1차 처리package org.springframework.web.servlet.mv..