Problem :
After updating to SpringBoot 3.2.0 everytime 404 NoResourceFoundException happened, it will re-route to 500 error due to default exception handler in @ControllerAdvice.
@ExceptionHandler
@ResponseStatus(INTERNAL_SERVER_ERROR)
fun handleAllOtherExceptions(ex: Exception) {
log.error(ex) { "exception occurred" }
}
How to reproduce :
- Clone example project on my Github
- Go to deployment/local and run sh start.sh (it will start docker container locally)
- Run SpringBoot application
- Test using Postman with invalid url :
localhost:8100/invalidURI/1 - To simulate success case, remove exception handler code bellow in class
RestExceptionHandler:
@ExceptionHandler
@ResponseStatus(INTERNAL_SERVER_ERROR)
fun handleAllOtherExceptions(ex: Exception) {
log.error(ex) { "exception occurred" }
}
Expected behaviour
- 404
NoResourceFoundExceptionshould not route to 500 error.
Comment From: wilkinsona
Duplicates https://github.com/spring-projects/spring-boot/issues/38733.