Skip to content

Commit 624be6d

Browse files
committed
Report bean creation failure in sortAdvisors as AopConfigException
Closes gh-32230
1 parent b08883b commit 624be6d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,9 @@
2020

2121
import org.springframework.aop.Advisor;
2222
import org.springframework.aop.TargetSource;
23+
import org.springframework.aop.framework.AopConfigException;
2324
import org.springframework.aop.support.AopUtils;
25+
import org.springframework.beans.factory.BeanCreationException;
2426
import org.springframework.beans.factory.BeanFactory;
2527
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2628
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
@@ -97,7 +99,13 @@ protected List<Advisor> findEligibleAdvisors(Class<?> beanClass, String beanName
9799
List<Advisor> eligibleAdvisors = findAdvisorsThatCanApply(candidateAdvisors, beanClass, beanName);
98100
extendAdvisors(eligibleAdvisors);
99101
if (!eligibleAdvisors.isEmpty()) {
100-
eligibleAdvisors = sortAdvisors(eligibleAdvisors);
102+
try {
103+
eligibleAdvisors = sortAdvisors(eligibleAdvisors);
104+
}
105+
catch (BeanCreationException ex) {
106+
throw new AopConfigException("Advisor sorting failed with unexpected bean creation, probably due " +
107+
"to custom use of the Ordered interface. Consider using the @Order annotation instead.", ex);
108+
}
101109
}
102110
return eligibleAdvisors;
103111
}

0 commit comments

Comments
 (0)