New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ControllerAdviceBean programatically is not possible. #32776
Comments
I agree with you, @sinanoezdemir , about your note on the Javadoc of ControllerAdviceBean (in the beginning of your comment). I, too, find the exact match between your statements and the Javadoc statements. That should be altered. However, pardon me for not diving deep into your usecase and context of micro services. |
Hello @sinanoezdemir , thanks for bringing this up. We have discussed this today as a team and I'll summarize here. We're not sure if you don't want your shared library to be scanned for components, or if it's scanned by micro-services but you would like to make this bit optional.
Are your applications using Spring Boot? If so, you could contribute your own auto-configurations and never rely on scanning for your library components. Your classes would still be annotated with Now depending on the outcome of this discussion, we might revisit the |
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: