001/* 002 * Copyright 2002-2013 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 org.springframework.beans.factory.config.BeanFactoryPostProcessor; 020import org.springframework.core.type.AnnotatedTypeMetadata; 021 022/** 023 * A single {@code condition} that must be {@linkplain #matches matched} in order 024 * for a component to be registered. 025 * 026 * <p>Conditions are checked immediately before the bean-definition is due to be 027 * registered and are free to veto registration based on any criteria that can 028 * be determined at that point. 029 * 030 * <p>Conditions must follow the same restrictions as {@link BeanFactoryPostProcessor} 031 * and take care to never interact with bean instances. For more fine-grained control 032 * of conditions that interact with {@code @Configuration} beans consider the 033 * {@link ConfigurationCondition} interface. 034 * 035 * @author Phillip Webb 036 * @since 4.0 037 * @see ConfigurationCondition 038 * @see Conditional 039 * @see ConditionContext 040 */ 041public interface Condition { 042 043 /** 044 * Determine if the condition matches. 045 * @param context the condition context 046 * @param metadata metadata of the {@link org.springframework.core.type.AnnotationMetadata class} 047 * or {@link org.springframework.core.type.MethodMetadata method} being checked. 048 * @return {@code true} if the condition matches and the component can be registered 049 * or {@code false} to veto registration. 050 */ 051 boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata); 052 053}