001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.core.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.core.Ordered;
026
027/**
028 * {@code @Order} defines the sort order for an annotated component.
029 *
030 * <p>The {@link #value} is optional and represents an order value as defined in the
031 * {@link Ordered} interface. Lower values have higher priority. The default value is
032 * {@code Ordered.LOWEST_PRECEDENCE}, indicating lowest priority (losing to any other
033 * specified order value).
034 *
035 * <p><b>NOTE:</b> Since Spring 4.0, annotation-based ordering is supported for many
036 * kinds of components in Spring, even for collection injection where the order values
037 * of the target components are taken into account (either from their target class or
038 * from their {@code @Bean} method). While such order values may influence priorities
039 * at injection points, please be aware that they do not influence singleton startup
040 * order which is an orthogonal concern determined by dependency relationships and
041 * {@code @DependsOn} declarations (influencing a runtime-determined dependency graph).
042 *
043 * <p>Since Spring 4.1, the standard {@link javax.annotation.Priority} annotation
044 * can be used as a drop-in replacement for this annotation in ordering scenarios.
045 * Note that {@code @Priority} may have additional semantics when a single element
046 * has to be picked (see {@link AnnotationAwareOrderComparator#getPriority}).
047 *
048 * <p>Alternatively, order values may also be determined on a per-instance basis
049 * through the {@link Ordered} interface, allowing for configuration-determined
050 * instance values instead of hard-coded values attached to a particular class.
051 *
052 * <p>Consult the javadoc for {@link org.springframework.core.OrderComparator
053 * OrderComparator} for details on the sort semantics for non-ordered objects.
054 *
055 * @author Rod Johnson
056 * @author Juergen Hoeller
057 * @since 2.0
058 * @see org.springframework.core.Ordered
059 * @see AnnotationAwareOrderComparator
060 * @see OrderUtils
061 * @see javax.annotation.Priority
062 */
063@Retention(RetentionPolicy.RUNTIME)
064@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
065@Documented
066public @interface Order {
067
068        /**
069         * The order value.
070         * <p>Default is {@link Ordered#LOWEST_PRECEDENCE}.
071         * @see Ordered#getOrder()
072         */
073        int value() default Ordered.LOWEST_PRECEDENCE;
074
075}