From 624be6d4e61fb0e5bc6e0665aef6d11cf09ea869 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 3 Jun 2024 12:46:14 +0200 Subject: [PATCH] Report bean creation failure in sortAdvisors as AopConfigException Closes gh-32230 --- .../autoproxy/AbstractAdvisorAutoProxyCreator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java index ca048cb9f1..7a71cb5756 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,9 @@ import java.util.List; import org.springframework.aop.Advisor; import org.springframework.aop.TargetSource; +import org.springframework.aop.framework.AopConfigException; import org.springframework.aop.support.AopUtils; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.annotation.AnnotationAwareOrderComparator; @@ -97,7 +99,13 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC List eligibleAdvisors = findAdvisorsThatCanApply(candidateAdvisors, beanClass, beanName); extendAdvisors(eligibleAdvisors); if (!eligibleAdvisors.isEmpty()) { - eligibleAdvisors = sortAdvisors(eligibleAdvisors); + try { + eligibleAdvisors = sortAdvisors(eligibleAdvisors); + } + catch (BeanCreationException ex) { + throw new AopConfigException("Advisor sorting failed with unexpected bean creation, probably due " + + "to custom use of the Ordered interface. Consider using the @Order annotation instead.", ex); + } } return eligibleAdvisors; }