Adding ControllerAdviceBean programatically is not possible. #32776
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: waiting-for-feedback
We need additional information before we can continue
status: waiting-for-triage
An issue we've not yet triaged or decided on
Enhancement/ Misleading description in javadoc.
In the Javadoc of
ControllerAdviceBean
you can readControllerAdviceBean
Reading this I assume, that it should be possible to create ControllerAdviceBeans and register them programmatically (without using the
@ControllerAdvice
annotation).As far as I understood the ExceptionHandlerExceptionResolver is the class keeping the ControllerAdviceBeans to apply matching ExceptionHandlers when an exception occurs.
However, when initialising the exceptionHandlerAdviceCache it uses ControllerAdviceBean.findAnnotatedBeans which scans the application context for beans annotated with
@ControllerAdvice
.The exceptionHandlerAdviceCache is otherwise not modifiable. So there is actually no other way to add ControllerAdviseBeans besides using the annotation.
I think that's why the Javadoc is misleading.
However, it would be great to have the ability to define ControllerAdviseBeans without using the
@ControllerAdvice
annotation.I assumed something similar to this should work.
Please excuse me if I misunderstood a concept here. Just trying to suggest an improvement.
The text was updated successfully, but these errors were encountered: