写点什么

SpringBootApplication 注解

用户头像
梦倚栏杆
关注
发布于: 2021 年 06 月 09 日

SpringBootApplication 是一个联合注解,但是到底都联合了哪些注解呢,容器启动过程中加载 bean 会用到,所以有必要看一下.

SpringBootApplication 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class))public @interface SpringBootApplication {
Class<?>[] exclude() default {};
String[] excludeName() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") String[] scanBasePackages() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses") Class<?>[] scanBasePackageClasses() default {};}
复制代码

ComponentScan 注解

@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)@Documented@Repeatable(ComponentScans.class)public @interface ComponentScan {   @AliasFor("basePackages")   String[] value() default {};   @AliasFor("value")   String[] basePackages() default {};   Class<?>[] basePackageClasses() default {};   Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;   Class<? extends ScopeMetadataResolver> scopeResolver() default AnnotationScopeMetadataResolver.class;   ScopedProxyMode scopedProxy() default ScopedProxyMode.DEFAULT;   String resourcePattern() default ClassPathScanningCandidateComponentProvider.DEFAULT_RESOURCE_PATTERN;   boolean useDefaultFilters() default true;   Filter[] includeFilters() default {};   Filter[] excludeFilters() default {};   boolean lazyInit() default false;   @Retention(RetentionPolicy.RUNTIME)   @Target({})   @interface Filter {      FilterType type() default FilterType.ANNOTATION;      @AliasFor("classes")      Class<?>[] value() default {};      @AliasFor("value")      Class<?>[] classes() default {};      String[] pattern() default {};   }}
复制代码

使用:生成 beanName 的时候不特别指定用的是 AnnotationBeanNameGenerator.class


SpringBootConfiguration 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Configurationpublic @interface SpringBootConfiguration {}
复制代码

Configuration 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Componentpublic @interface Configuration {   String value() default "";}
复制代码

Component 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Component {   /**    * The value may indicate a suggestion for a logical component name,    * to be turned into a Spring bean in case of an autodetected component.    * @return the suggested component name, if any    */   String value() default "";}
复制代码


EnableAutoConfiguration 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@AutoConfigurationPackage@Import(EnableAutoConfigurationImportSelector.class)public @interface EnableAutoConfiguration {   String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";   Class<?>[] exclude() default {};   String[] excludeName() default {};}
复制代码

AutoConfigurationPackage 注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@Import(AutoConfigurationPackages.Registrar.class)public @interface AutoConfigurationPackage {
}
复制代码

Import 注解

ConfigurationClassParser 里有关于 import 的处理

public @interface Import {
/** * {@link Configuration}, {@link ImportSelector}, {@link ImportBeanDefinitionRegistrar} * or regular component classes to import. */ Class<?>[] value();
}
复制代码


Bean 注解

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Bean {
/** * Alias for {@link #name}. * <p>Intended to be used when no other attributes are needed, for example: * {@code @Bean("customBeanName")}. * @since 4.3.3 * @see #name */ @AliasFor("name") String[] value() default {};
/** * The name of this bean, or if several names, a primary bean name plus aliases. * <p>If left unspecified, the name of the bean is the name of the annotated method. * If specified, the method name is ignored. * <p>The bean name and aliases may also be configured via the {@link #value} * attribute if no other attributes are declared. * @see #value */ @AliasFor("value") String[] name() default {};
/** * Are dependencies to be injected via convention-based autowiring by name or type? * <p>Note that this autowire mode is just about externally driven autowiring based * on bean property setter methods by convention, analogous to XML bean definitions. * <p>The default mode does allow for annotation-driven autowiring. "no" refers to * externally driven autowiring only, not affecting any autowiring demands that the * bean class itself expresses through annotations. * @see Autowire#BY_NAME * @see Autowire#BY_TYPE */ Autowire autowire() default Autowire.NO;
String initMethod() default ""; String destroyMethod() default AbstractBeanDefinition.INFER_METHOD;
}
复制代码


注解表整理


@Bean 注解类 beanName 定义:


发布于: 2021 年 06 月 09 日阅读数: 10
用户头像

梦倚栏杆

关注

还未添加个人签名 2018.04.22 加入

还未添加个人简介

评论

发布
暂无评论
SpringBootApplication注解