spring-boot: `spring.mvc.log-resolved-exception` gets enabled by default.
Hi.
I’m using Spring Boot 2.6.3 and from the moment I’ve defined a ResponseEntityExceptionHandler I get an annoying warning log in the console of the type WARN 7072 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [<fully-qualified-class-name>: <message>].
The handler is the following:
/**
* @author Cosimo Damiano Prete
* @since 09/02/2022
*/
@ControllerAdvice
class WebServiceExceptionHandler extends ResponseEntityExceptionHandler {
@Valid
@ExceptionHandler(ClientHttpException.class)
public ResponseEntity<Object> handleClientHttpException(ClientHttpException ex, WebRequest request) {
return handleExceptionInternal(ex, ErrorResponse.fromClientHttpException(ex), new HttpHeaders(), ex.statusCode(), request);
}
private record ErrorResponse(String code, String defaultMessage) {
private static <E extends ClientHttpException> ErrorResponse fromClientHttpException(E ex) {
return new ErrorResponse(ex.clientCode(), ex.getMessage());
}
}
}
By putting a breakpoint in the setter of WebMvcProperties I can see it actually gets called with the value true even though I don’t have such value set at all in my application.yml file.
Strangely enough, if I explicitly set it to false then it stays like that (probably my props are applied later).
The issue doesn’t seem to be caused by the ResponseEntityExceptionHandler, since I get the same also when the handler is defined as
/**
* @author Cosimo Damiano Prete
* @since 09/02/2022
*/
@ControllerAdvice
class WebServiceExceptionHandler {
@ExceptionHandler(ClientHttpException.class)
ResponseEntity<ErrorResponse> handleClientHttpException(ClientHttpException ex) {
return new ResponseEntity<>(ErrorResponse.fromClientHttpException(ex), ex.statusCode());
}
private record ErrorResponse(String code, String defaultMessage) {
private static <E extends ClientHttpException> ErrorResponse fromClientHttpException(E ex) {
return new ErrorResponse(ex.clientCode(), ex.getMessage());
}
}
}
I’ve also tried adding an @Order annotation with highest priority (so that it would trigger my advice first), but it didn’t help.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (9 by maintainers)
Commits related to this issue
- Demo app for https://github.com/spring-projects/spring-boot/issues/29706 — committed to cdprete/github_spring_boot_issue_29706 by pretecd 2 years ago
- Demo app for https://github.com/spring-projects/spring-boot/issues/29706 — committed to cdprete/github_spring_boot_issue_29706 by pretecd 2 years ago
- Demo app for https://github.com/spring-projects/spring-boot/issues/29706 — committed to cdprete/github_spring_boot_issue_29706 by pretecd 2 years ago
@cdprete Are you using DevTools? It enables logging of resolved exceptions by default:
https://github.com/spring-projects/spring-boot/blob/067a8dd3ecb4c02ec4ee771f36a9320e3c4c8a53/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java#L73
The complete sample that Scott has requested a couple of times would have answered this definitively.