Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @RestControllerAdvice in Standalone MockMvc again
Since Spring Framework 5.2, @RestControllerAdvice registered with MockMvc when using MockMvcBuilders.standaloneSetup() has no longer been properly supported if annotation attributes were declared in the @RestControllerAdvice annotation. Prior to 5.2, this was not an issue. The cause for this regression is two-fold. 1. Commit 50c2577 refactored DefaultListableBeanFactory so that findAnnotationOnBean() supports merged annotations; however, that commit did not refactor StaticListableBeanFactory#findAnnotationOnBean() to support merged annotations. 2. Commit 978adbd refactored ControllerAdviceBean so that a merged @ControllerAdvice annotation is only looked up via ApplicationContext#findAnnotationOnBean(). The latter relies on the fact that findAnnotationOnBean() supports merged annotations (e.g., @RestControllerAdvice as a merged instance of @ControllerAdvice). Behind the scenes, MockMvcBuilders.standaloneSetup() creates a StubWebApplicationContext which internally uses a StubBeanFactory which extends StaticListableBeanFactory. Consequently, since the implementation of findAnnotationOnBean() in StaticListableBeanFactory was not updated to support merged annotations like it was in DefaultListableBeanFactory, we only see this regression with the standalone MockMvc support and not with MockMvc support for an existing WebApplicationContext or with standard Spring applications using an ApplicationContext that uses DefaultListableBeanFactory. This commit fixes this regression by supporting merged annotations in StaticListableBeanFactory#findAnnotationOnBean() as well. Closes gh-25520
- Loading branch information
Showing
3 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters