Skip to content

AnnotationAwareOrderComparator getPriority does not work if bean is a proxy [SPR-13884] #18457

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 6e3fac8

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions