Introduce findAnnotatedBeans(ListableBeanFactory) in ControllerAdviceBean

This commit introduces a new findAnnotatedBeans(ListableBeanFactory)
override for the existing findAnnotatedBeans(ApplicationContext) method.

Closes gh-35571
This commit is contained in:
Sam Brannen 2025-10-07 12:37:07 +02:00
parent 6aeb9d16e8
commit ff9a349271
1 changed files with 16 additions and 4 deletions

View File

@ -228,14 +228,26 @@ public class ControllerAdviceBean implements Ordered {
* instances.
* <p>Note that the {@code ControllerAdviceBean} instances in the returned list
* are sorted using {@link OrderComparator#sort(List)}.
* @see #findAnnotatedBeans(ListableBeanFactory)
*/
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context) {
return findAnnotatedBeans((ListableBeanFactory) context);
}
/**
* Find beans annotated with {@link ControllerAdvice @ControllerAdvice} in the
* given {@link ListableBeanFactory} and wrap them as {@code ControllerAdviceBean}
* instances.
* <p>Note that the {@code ControllerAdviceBean} instances in the returned list
* are sorted using {@link OrderComparator#sort(List)}.
* @since 7.0
* @see #getOrder()
* @see OrderComparator
* @see Ordered
*/
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context) {
ListableBeanFactory beanFactory = context;
if (context instanceof ConfigurableApplicationContext cac) {
// Use internal BeanFactory for potential downcast to ConfigurableBeanFactory above
public static List<ControllerAdviceBean> findAnnotatedBeans(ListableBeanFactory beanFactory) {
if (beanFactory instanceof ConfigurableApplicationContext cac) {
// Use internal BeanFactory for potential downcast to ConfigurableBeanFactory in getOrder().
beanFactory = cac.getBeanFactory();
}
List<ControllerAdviceBean> adviceBeans = new ArrayList<>();