diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
index 09c83104f37..316220dfdc6 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
@@ -29,6 +29,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
@@ -2315,6 +2316,33 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return (result instanceof Optional> optional ? optional : Optional.ofNullable(result));
}
+ /**
+ * Public method to determine the applicable order value for a given bean.
+ *
This variant implicitly obtains a corresponding bean instance from this factory.
+ * @param beanName the name of the bean
+ * @return the corresponding order value (default is {@link Ordered#LOWEST_PRECEDENCE})
+ * @since 7.0
+ * @see #getOrder(String, Object)
+ */
+ public int getOrder(String beanName) {
+ return getOrder(beanName, getBean(beanName));
+ }
+
+ /**
+ * Public method to determine the applicable order value for a given bean.
+ * @param beanName the name of the bean
+ * @param beanInstance the bean instance to check
+ * @return the corresponding order value (default is {@link Ordered#LOWEST_PRECEDENCE})
+ * @since 7.0
+ * @see #getOrder(String)
+ */
+ public int getOrder(String beanName, Object beanInstance) {
+ OrderComparator comparator = (getDependencyComparator() instanceof OrderComparator orderComparator ?
+ orderComparator : OrderComparator.INSTANCE);
+ return comparator.getOrder(beanInstance,
+ new FactoryAwareOrderSourceProvider(Collections.singletonMap(beanInstance, beanName)));
+ }
+
@Override
public String toString() {
@@ -2672,7 +2700,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return null;
}
try {
- RootBeanDefinition beanDefinition = (RootBeanDefinition) getMergedBeanDefinition(beanName);
+ BeanDefinition beanDefinition = getMergedBeanDefinition(beanName);
List