@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 {
……
复合注解:包含@EnableAutoConfiguration、@ComponentScan、@SpringBootConfiguration
a 、@EnableAutoConfiguration:也是复合注解、借助@Import将所有符合自动配置条件的bean定义加载到Spring ioc 中。帮助springboot应用将所有符合条件的@configuration配置都加载到当前spring ioc。
@Import注解的使用。这个注解帮助我们将多个配置文件(可能是按功能分,或是按业务分)导入到单个主配置中,以避免将所有配置写在一个配置中
b、@ComponentScan:主要作用扫描当前包及其子包下被@Component,@Controller,@Service,@Repository注解标记的类并纳入到spring容器中进行管理。是以前的<context:component-scan>(以前使用在xml中使用的标签,用来扫描包配置的平行支持)。可通过@ComponentScan 的basepackage等属性来指定扫描范围。(@SpringBootApplication(scanBasePackages = "com.ucredit")。如果不指定默认spring框架实现,从声明@ComponentScan所在的类的package进行扫描。所以springboot的启动类最好放在root package下。
c、@SpringBootConfiguration:继承自@Configuration,二者功能也一致,标注当前类是配置类,并会将当前类内声明的一个或多个以@Bean注解标记的方法的实例纳入到spring容器中,并且实例名就是方法名。@SpringBootConfiguration注解类相当于spring配置bean的xml文件。
d、@Configuration
Spring是给予IOC的,在4.0之前的版本,通常都是程序依赖上下文xml文件来管理bean,尽管有了扫描配置后相对简单,然而java配置的方式不同于xml,通过注解能够更简单