001/*
002 * Copyright 2012-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 *      http://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.boot.autoconfigure;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Inherited;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.lang.annotation.Target;
025
026import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
027import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
028import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
029import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
030import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
031import org.springframework.context.annotation.Conditional;
032import org.springframework.context.annotation.Configuration;
033import org.springframework.context.annotation.Import;
034import org.springframework.core.io.support.SpringFactoriesLoader;
035
036/**
037 * Enable auto-configuration of the Spring Application Context, attempting to guess and
038 * configure beans that you are likely to need. Auto-configuration classes are usually
039 * applied based on your classpath and what beans you have defined. For example, if you
040 * have {@code tomcat-embedded.jar} on your classpath you are likely to want a
041 * {@link TomcatServletWebServerFactory} (unless you have defined your own
042 * {@link ServletWebServerFactory} bean).
043 * <p>
044 * When using {@link SpringBootApplication}, the auto-configuration of the context is
045 * automatically enabled and adding this annotation has therefore no additional effect.
046 * <p>
047 * Auto-configuration tries to be as intelligent as possible and will back-away as you
048 * define more of your own configuration. You can always manually {@link #exclude()} any
049 * configuration that you never want to apply (use {@link #excludeName()} if you don't
050 * have access to them). You can also exclude them via the
051 * {@code spring.autoconfigure.exclude} property. Auto-configuration is always applied
052 * after user-defined beans have been registered.
053 * <p>
054 * The package of the class that is annotated with {@code @EnableAutoConfiguration},
055 * usually via {@code @SpringBootApplication}, has specific significance and is often used
056 * as a 'default'. For example, it will be used when scanning for {@code @Entity} classes.
057 * It is generally recommended that you place {@code @EnableAutoConfiguration} (if you're
058 * not using {@code @SpringBootApplication}) in a root package so that all sub-packages
059 * and classes can be searched.
060 * <p>
061 * Auto-configuration classes are regular Spring {@link Configuration} beans. They are
062 * located using the {@link SpringFactoriesLoader} mechanism (keyed against this class).
063 * Generally auto-configuration beans are {@link Conditional @Conditional} beans (most
064 * often using {@link ConditionalOnClass @ConditionalOnClass} and
065 * {@link ConditionalOnMissingBean @ConditionalOnMissingBean} annotations).
066 *
067 * @author Phillip Webb
068 * @author Stephane Nicoll
069 * @see ConditionalOnBean
070 * @see ConditionalOnMissingBean
071 * @see ConditionalOnClass
072 * @see AutoConfigureAfter
073 * @see SpringBootApplication
074 */
075@Target(ElementType.TYPE)
076@Retention(RetentionPolicy.RUNTIME)
077@Documented
078@Inherited
079@AutoConfigurationPackage
080@Import(AutoConfigurationImportSelector.class)
081public @interface EnableAutoConfiguration {
082
083        String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
084
085        /**
086         * Exclude specific auto-configuration classes such that they will never be applied.
087         * @return the classes to exclude
088         */
089        Class<?>[] exclude() default {};
090
091        /**
092         * Exclude specific auto-configuration class names such that they will never be
093         * applied.
094         * @return the class names to exclude
095         * @since 1.3.0
096         */
097        String[] excludeName() default {};
098
099}