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 JPA : Java 날짜/시간 데이터 타입과 JPA, MySQL 타임존의 관계Spring Boot 2024. 4. 11. 01:42
Java 타입과 MySQL 저장 타입별 분석 최종 결론타임존이 필요한 시간을 저장할 때는 ZonedDateTime을 MySQL의 datetime에 저장하는 방식을 사용하자.장점: 다른 어떤 타임존 설정에도 영향받지 않는다.단점(아닐 수도): DB에는 항상 UTC 기준 시간으로 저장되고 조회된다.Java의 Date 타입은 DB 타임존과 DB 세션 타임존을 일치시켜서 MySQL의 timestamp에 저장해야 정확한 시간 값을 저장하고 조회할 수 있다.Java의 Calendar 타입은 DB 타임존과 DB 세션 타임존, Calendar 타임존을 일치시켜서 MySQL의 timestamp에 저장해야 정확한 시간 값을 저장하고 조회할 수 있다.Java의 LocalDateTime 타입은 시스템 기본 타임존과 DB 세션..
-
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..