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.context.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
025/**
026 * Indicates that a component is only eligible for registration when all
027 * {@linkplain #value specified conditions} match.
028 *
029 * <p>A <em>condition</em> is any state that can be determined programmatically
030 * before the bean definition is due to be registered (see {@link Condition} for details).
031 *
032 * <p>The {@code @Conditional} annotation may be used in any of the following ways:
033 * <ul>
034 * <li>as a type-level annotation on any class directly or indirectly annotated with
035 * {@code @Component}, including {@link Configuration @Configuration} classes</li>
036 * <li>as a meta-annotation, for the purpose of composing custom stereotype
037 * annotations</li>
038 * <li>as a method-level annotation on any {@link Bean @Bean} method</li>
039 * </ul>
040 *
041 * <p>If a {@code @Configuration} class is marked with {@code @Conditional},
042 * all of the {@code @Bean} methods, {@link Import @Import} annotations, and
043 * {@link ComponentScan @ComponentScan} annotations associated with that
044 * class will be subject to the conditions.
045 *
046 * <p><strong>NOTE</strong>: Inheritance of {@code @Conditional} annotations
047 * is not supported; any conditions from superclasses or from overridden
048 * methods will not be considered. In order to enforce these semantics,
049 * {@code @Conditional} itself is not declared as
050 * {@link java.lang.annotation.Inherited @Inherited}; furthermore, any
051 * custom <em>composed annotation</em> that is meta-annotated with
052 * {@code @Conditional} must not be declared as {@code @Inherited}.
053 *
054 * @author Phillip Webb
055 * @author Sam Brannen
056 * @since 4.0
057 * @see Condition
058 */
059@Target({ElementType.TYPE, ElementType.METHOD})
060@Retention(RetentionPolicy.RUNTIME)
061@Documented
062public @interface Conditional {
063
064        /**
065         * All {@link Condition}s that must {@linkplain Condition#matches match}
066         * in order for the component to be registered.
067         */
068        Class<? extends Condition>[] value();
069
070}