I have problems understanding on why ExceptionHandlerExceptionResolver throws an Exception. I have written a custom @RestControllerAdvice ExceptionHandler to catch Exceptions thrown by my Spring Boot application. After the catch my ExceptionHandler returns as a response the message from the thrown exception. But I still get a log message from ExceptionHandlerExceptionResolver and I can't figure out why.
Here the Log message:
2022-05-04 10:08:53.043 INFO 17600 --- [nio-8080-exec-3] at.sds.wm.common.CommonExceptionHandler : Equipment Barbell 660Kg exists already. Either id already taken or name combined with same equipment already saved
2022-05-04 10:08:53.049 WARN 17600 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [at.sds.wm.equipment.exceptions.EquipmentExistsAlreadyException: Equipment Barbell 660Kg exists already. Either id already taken or name combined with same equipment already saved]
I first thought, that the ExceptionHandlerExceptionResolver gets called because my ExceptionHandler throws an Exception but that isn't the case.
Any tips and tricks on how to surpress the second Log, or could someone explain me why the ExceptionHandlerExceptionResolver gets called?
Below my code snippet for the ExceptionHandler part that gets called:
@ExceptionHandler(value = {WorkoutExistsAlreadyException.class, EquipmentExistsAlreadyException.class, ExerciseExistsAlreadyException.class})
@ResponseStatus(code = HttpStatus.CONFLICT)
public String handleExistsAlreadyException(RuntimeException ex) {
log.info(ex.getMessage());
return ex.getMessage();
}
CodePudding user response:
This is related with the application property spring.mvc.log-resolved-exception
. This is by default set to false in spring-boot
but if you use spring-boot-devtools
then it is switched to true.
So in that case you have to declare spring.mvc.log-resolved-exception = false
for exception handler resolver to stop writting warns about exceptions.