zoukankan      html  css  js  c++  java
  • SpringBoot之注解

    1、@SpringBootApplication

        @SpringBootApplication标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot就该运行这个类的main方法启动SpringBoot应用

        

    @SpringBootApplication注解内部: 

    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Inherited
    @SpringBootConfiguration
    @EnableAutoConfiguration
    @ComponentScan(
        excludeFilters = {@Filter(
        type = FilterType.CUSTOM,
        classes = {TypeExcludeFilter.class}
    ), @Filter(
        type = FilterType.CUSTOM,
        classes = {AutoConfigurationExcludeFilter.class}
    )}
    )
    public @interface SpringBootApplication {
      @SpringBootConfiguration:SpringBoot的配置类,标注在类上,表示是SpringBoot的配置类【这个是SpringBoot规定的注解】
        内部:
    @Configuration配置类上来标注的注解【这个是Spring规定的注解】
            配置类也是容器中的一个组件:@Component

    2、@EnableAutoConfiguration

       开启自动配置功能,以前要配置的比如扫描什么的,现在都不需要手写了,SpringBoot自动装配,@EnableAutoConfiguration告诉SpeingBoot开启自动配置;这样才能生效

    内部也是组合注解:

    @AutoConfigurationPackage
    @Import({EnableAutoConfigurationImportSelector.class})
    public @interface EnableAutoConfiguration {
    @AutoConfigurationPackage:自动配置包
        
    @Import({Registrar.class})
          Spring的底层注解@import,给容器导入一个组件;导入的组件
    Registrar.class将主配置类(就是@SpringBootApplication标注的类)所在的包以及下面所有子
    包里面的所有组件都扫描到Spring容器中
    @Import({EnableAutoConfigurationImportSelector.class})
      导入那些组件的选择器,将需要的组件以全类名(
    String[] selectImports(AnnotationMetadata annotationMetadata){}
    )的方式返回。这些组件就会添加到容器中;会给容器中导入非常多的配置类(xxxAutoConfiguration);就是给容器中导入这个场景需要的所有组件,并配置好这些组件;
    有了自动配置类,就免去了手动编写配置注入功能组件的工作;
     
     
     
  • 相关阅读:
    Kafka 生产者 自定义分区策略
    同步互斥
    poj 1562 Oil Deposits(dfs)
    poj 2386 Lake Counting(dfs)
    poj 1915 KnightMoves(bfs)
    poj 1664 放苹果(dfs)
    poj 1543 Perfect Cubes (暴搜)
    poj 1166 The Clocks (暴搜)
    poj 3126 Prime Path(bfs)
    处理机调度
  • 原文地址:https://www.cnblogs.com/Timeouting-Study/p/13212395.html
Copyright © 2011-2022 走看看