Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Mar 18, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    As of 4.3, AnnotationAwareOrderComparator checks for the new DecoratingProxy interface, introspecting the decorated class behind a proxy as well. Interface-based Spring AOP proxy automatically expose this now, even behind multiple nested proxies.

    With respect to @Order versus @Priority: This is actually intended... An order is just that: a sort order, whereas a priority also implies primary characteristics for the first element in the list. So in Spring terms, the use of @Priority kind of combines @Order with an @Primary marker for the first element.

    Juergen

  2. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions