Detect Order on target class as well
Previously, the `@Order` annotation was managed in an inconsistent way when placed at the implementation level. For simple beans, it was discovered properly but wasn't for beans requiring a proxy. OrderComparator.SourceProvider now explicitly allows to return several order sources; the default implementation returns not only the factory method (if any) but also the target class if it happens to be different from the class of the bean. Issue: SPR-12636
This commit is contained in:
@@ -1459,14 +1459,27 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
|
||||
@Override
|
||||
public Object getOrderSource(Object obj) {
|
||||
return getFactoryMethod(this.instancesToBeanNames.get(obj));
|
||||
RootBeanDefinition beanDefinition = getRootBeanDefinition(this.instancesToBeanNames.get(obj));
|
||||
if (beanDefinition == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> sources = new ArrayList<Object>();
|
||||
Method factoryMethod = beanDefinition.getResolvedFactoryMethod();
|
||||
if (factoryMethod != null) {
|
||||
sources.add(factoryMethod);
|
||||
}
|
||||
Class<?> targetType = beanDefinition.getTargetType();
|
||||
if (targetType != null && !targetType.equals(obj.getClass())) {
|
||||
sources.add(targetType);
|
||||
}
|
||||
return sources.toArray(new Object[sources.size()]);
|
||||
}
|
||||
|
||||
private Method getFactoryMethod(String beanName) {
|
||||
private RootBeanDefinition getRootBeanDefinition(String beanName) {
|
||||
if (beanName != null && containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = getMergedBeanDefinition(beanName);
|
||||
if (bd instanceof RootBeanDefinition) {
|
||||
return ((RootBeanDefinition) bd).getResolvedFactoryMethod();
|
||||
return (RootBeanDefinition) bd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user