[SPRING] Spring Boot Rest Controller에서 기본 JSON 오류 응답 수정
SPRINGSpring Boot Rest Controller에서 기본 JSON 오류 응답 수정
현재 스프링 부트의 오류 응답에는 다음과 같은 표준 컨텐트가 들어 있습니다.
{
"timestamp" : 1426615606,
"exception" : "org.springframework.web.bind.MissingServletRequestParameterException",
"status" : 400,
"error" : "Bad Request",
"path" : "/welcome",
"message" : "Required String parameter 'name' is not present"
}
나는 응답에서 "예외"속성을 없애는 방법을 찾고있다. 이것을 달성 할 수있는 방법이 있습니까?
해결법
-
==============================
1.에러 핸들링에 대한 문서에서 설명한 것처럼, ErrorAttributes를 구현 한 자신 만의 bean을 제공하여 컨텐츠를 제어 할 수 있습니다.
에러 핸들링에 대한 문서에서 설명한 것처럼, ErrorAttributes를 구현 한 자신 만의 bean을 제공하여 컨텐츠를 제어 할 수 있습니다.
쉬운 방법은 DefaultErrorAttributes를 서브 클래 싱하는 것입니다. 예 :
@Bean public ErrorAttributes errorAttributes() { return new DefaultErrorAttributes() { @Override public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) { Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace); // Customize the default entries in errorAttributes to suit your needs return errorAttributes; } }; }
from https://stackoverflow.com/questions/29106637/modify-default-json-error-response-from-spring-boot-rest-controller by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] Grails 파일 다운로드 (0) | 2019.01.10 |
---|---|
[SPRING] Spring의 ConversionService (0) | 2019.01.10 |
[SPRING] persistence.xml없이 Spring을 설정하는 방법은? (0) | 2019.01.10 |
[SPRING] 싱글 톤과 프로토 타입 빈의 차이점은 무엇입니까? (0) | 2019.01.10 |
[SPRING] 프로그래밍 방식으로 Spring에서 속성 자리 표시자를 결정하는 방법 (0) | 2019.01.10 |