Description
Martin Frey opened SPR-13884 and commented
Identified a bug in the AnnotationAwareOrderComparator
during investigating a NonUniqueBeanException
with beans using the @Order
/ @Priority
annotation.
First finding = bug:
The method AnnotationAwareOrderComparator.getPriority
calls directly getClass()
on the given beanInstance. This leads to no priority at all as the Proxy class (JdkProxy) does not contain the annotation. The fix seems reasonably easy: Just use the AopUtils.getTargetClass(beanInstance)
instead of getClass()
.
AnnotationAwareOrderComparator
public Integer getPriority(Object obj) {
if (obj instanceof Class) {
return OrderUtils.getPriority((Class<?>) obj);
} else if (obj != null) {
return OrderUtils.getPriority(AopUtils.getTargetClass(obj));
}
return null;
}
Second finding = just to clarify:
Not sure if both @Order
and @Priority
should be supported by this? Currently only @Priority
or @Primary
seems to be used to identify autowire candidates via the DefaultListableBeanFactory.determineAutowireCandidate
. Is this the desired behavior or should also the @Order
annotation be considered here? As far as i remember @Priority
was first introduced to support @Order
with the standard API, and later also used to identify Primary candidates?
Affects: 4.2.3
Issue Links:
- DefaultAdvisorAutoProxyCreator doesn't get the target class of existing proxy [SPR-13990] #18563 DefaultAdvisorAutoProxyCreator doesn't get the target class of existing proxy
- GenericConversionService.addConverter should be able to determine generic types from target class behind proxy [SPR-14822] #19388 GenericConversionService.addConverter should be able to determine generic types from target class behind proxy
Referenced from: commits 6e3fac8