注解定义
1 @Target( {ElementType.TYPE}) 2 @Retention(RetentionPolicy.RUNTIME) 3 @Documented 4 @Inherited 5 @SpringBootConfiguration 6 @EnableAutoConfiguration 7 @ComponentScan(excludeFilters = { 8 @Filter(type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class}), 9 @Filter(type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class}) 10 }) 11 public @interface SpringBootApplication { 12 @AliasFor(annotation = EnableAutoConfiguration.class) Class<?>[] exclude() default {}; 13 14 @AliasFor(annotation = EnableAutoConfiguration.class) String[] excludeName() default {}; 15 16 @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") String[] scanBasePackages() default {}; 17 18 @AliasFor(annotation = ComponentScan.class, 19 attribute = "basePackageClasses") Class<?>[] scanBasePackageClasses() default {}; 20 21 @AliasFor(annotation = ComponentScan.class, 22 attribute = "nameGenerator") Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class; 23 24 @AliasFor(annotation = Configuration.class) boolean proxyBeanMethods() default true; 25 }
@SpringBootConfiguration
- @Configuration
@EnableAutoConfiguration
- @AutoConfigurationPackage
-- @Import({Registrar.class})
static class Registrar implements ImportBeanDefinitionRegistrar, DeterminableImports { Registrar() { } public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { AutoConfigurationPackages.register(registry, (String[])(new AutoConfigurationPackages.PackageImports(metadata)).getPackageNames().toArray(new String[0])); } public Set<Object> determineImports(AnnotationMetadata metadata) { return Collections.singleton(new AutoConfigurationPackages.PackageImports(metadata)); } }
- @Import({AutoConfigurationImportSelector.class})
- {String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";}
public class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered { private static final AutoConfigurationImportSelector.AutoConfigurationEntry EMPTY_ENTRY = new AutoConfigurationImportSelector.AutoConfigurationEntry(); private static final String[] NO_IMPORTS = new String[0]; private static final Log logger = LogFactory.getLog(AutoConfigurationImportSelector.class); private static final String PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE = "spring.autoconfigure.exclude"; private ConfigurableListableBeanFactory beanFactory; private Environment environment; private ClassLoader beanClassLoader; private ResourceLoader resourceLoader; private AutoConfigurationImportSelector.ConfigurationClassFilter configurationClassFilter;