Annotation Interface Order


@Retention(RUNTIME) @Target({TYPE,METHOD,FIELD}) @Documented public @interface Order
Annotation for objects that are ordered.

Order in a Micronaut application is important in multiple aspects including but note limited to:

  • Controlling bean selection and prioritization
  • Ordering injected List collections.
  • Ordering AOP method interceptors
  • Ordering HTTP filters

This annotation can be used to control the order by specifying a numerical value that sorts components in the desired order

The lowest value takes precedence: a component annotated @Order(1) comes before one annotated @Order(100), and Ordered.HIGHEST_PRECEDENCE is the most negative value rather than the largest one.

jakarta.annotation.Priority is mapped to this annotation at compile time with its value unchanged, so a bean annotated @Priority(10) orders as @Order(10) and the lowest priority value wins. That is the direction Jakarta Interceptors and Jakarta RESTful Web Services give the priorities they define; a specification that prefers the highest value instead, such as the selection of a CDI alternative, needs the value negated by whoever reads it. The mapping adds to the metadata rather than replacing it, so jakarta.annotation.Priority is still readable as written alongside the mapped order.

Since:
2.0
Author:
Sean Carroll
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The order value.
  • Element Details

    • value

      int value
      The order value. Defaults to zero (no order).
      Returns:
      the order
      Default:
      0