It didn’t work as expected because this type of error occurs during the initialization of the Spring context, before the controllers are fully ready. So, your @ControllerAdvice cannot intercept this exception, I think.
Maybe this could help you: Baeldung - spring-boot-failure-analyzer