Document common use cases for @Order vs @Priority vs @DependsOn
Issue: SPR-16213
(cherry picked from commit 84699c8)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,21 +27,29 @@ import org.springframework.core.Ordered;
|
||||
/**
|
||||
* {@code @Order} defines the sort order for an annotated component.
|
||||
*
|
||||
* <p>The {@link #value} is optional and represents an order value as defined
|
||||
* in the {@link Ordered} interface. Lower values have higher priority. The
|
||||
* default value is {@code Ordered.LOWEST_PRECEDENCE}, indicating
|
||||
* lowest priority (losing to any other specified order value).
|
||||
* <p>The {@link #value} is optional and represents an order value as defined in the
|
||||
* {@link Ordered} interface. Lower values have higher priority. The default value is
|
||||
* {@code Ordered.LOWEST_PRECEDENCE}, indicating lowest priority (losing to any other
|
||||
* specified order value).
|
||||
*
|
||||
* <p>Since Spring 4.1, the standard {@link javax.annotation.Priority}
|
||||
* annotation can be used as a drop-in replacement for this annotation.
|
||||
* <p><b>NOTE:</b> Since Spring 4.0, annotation-based ordering is supported for many
|
||||
* kinds of components in Spring, even for collection injection where the order values
|
||||
* of the target components are taken into account (either from their target class or
|
||||
* from their {@code @Bean} method). While such order values may influence priorities
|
||||
* at injection points, please be aware that they do not influence singleton startup
|
||||
* order which is an orthogonal concern determined by dependency relationships and
|
||||
* {@code @DependsOn} declarations (influencing a runtime-determined dependency graph).
|
||||
*
|
||||
* <p><b>NOTE</b>: Annotation-based ordering is supported for specific kinds
|
||||
* of components only — for example, for annotation-based AspectJ
|
||||
* aspects. Ordering strategies within the Spring container, on the other
|
||||
* hand, are typically based on the {@link Ordered} interface in order to
|
||||
* allow for programmatically configurable ordering of each <i>instance</i>.
|
||||
* <p>Since Spring 4.1, the standard {@link javax.annotation.Priority} annotation
|
||||
* can be used as a drop-in replacement for this annotation in ordering scenarios.
|
||||
* Note that {@code Priority} may have additional semantics when a single element
|
||||
* has to be picked (see {@link AnnotationAwareOrderComparator#getPriority}).
|
||||
*
|
||||
* <p>Consult the Javadoc for {@link org.springframework.core.OrderComparator
|
||||
* <p>Alternatively, order values may also be determined on a per-instance basis
|
||||
* through the {@link Ordered} interface, allowing for configuration-determined
|
||||
* instance values instead of hard-coded values attached to a particular class.
|
||||
*
|
||||
* <p>Consult the javadoc for {@link org.springframework.core.OrderComparator
|
||||
* OrderComparator} for details on the sort semantics for non-ordered objects.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
|
||||
Reference in New Issue
Block a user