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 ca048cb9f17..7a71cb57569 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; } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java index fedf491617b..124b1612acd 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -36,6 +36,7 @@ import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.refl * Tests for {@link AspectJAdvisorBeanRegistrationAotProcessor}. * * @author Sebastien Deleuze + * @since 6.1 */ class AspectJAdvisorBeanRegistrationAotProcessorTests { @@ -43,8 +44,9 @@ class AspectJAdvisorBeanRegistrationAotProcessorTests { private final RuntimeHints runtimeHints = this.generationContext.getRuntimeHints(); + @Test - void shouldProcessesAspectJClass() { + void shouldProcessAspectJClass() { process(AspectJClass.class); assertThat(reflection().onType(AspectJClass.class).withMemberCategory(MemberCategory.DECLARED_FIELDS)) .accepts(this.runtimeHints); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 34a59d67208..506e286030d 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -1052,16 +1052,16 @@ public abstract class AnnotationUtils { return null; } try { - Method method = annotation.annotationType().getDeclaredMethod(attributeName); - return invokeAnnotationMethod(method, annotation); - } - catch (NoSuchMethodException ex) { - return null; + for (Method method : annotation.annotationType().getDeclaredMethods()) { + if (method.getName().equals(attributeName) && method.getParameterCount() == 0) { + return invokeAnnotationMethod(method, annotation); + } + } } catch (Throwable ex) { handleValueRetrievalFailure(annotation, ex); - return null; } + return null; } /**