I recently upgraded to Spring Boot 3.5 (Jakarta packages) and noticed my global exception handler isn’t being triggered.
@RestController
public class UserController {
@GetMapping("/test")
public String test() {
throw new MyBusinessException("Something went wrong");
}
}
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(MyBusinessException.class)
public ProblemDetail handleMyBusinessException(MyBusinessException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage());
}
}
public class MyBusinessException extends RuntimeException {
public MyBusinessException(String message) { super(message); }
}
When I call /test, I still get the default 500 response instead of my custom ProblemDetail.
I’ve verified:
Packages are under the same base package.
Using jakarta.* imports.
No custom filters or resolvers.
Question:
Why isn’t my @RestControllerAdvice handler being called in Spring Boot 3.x, and how can I fix it so it returns my custom JSON response?
UserController::testmethod? in test or via postman/curl? If in test, show your test code please