@SpringBootApplication 组合注解包含哪些注解及作用

序:在学习springboot,教程一般对一些注解语焉不详,发现@SpringBootApplication 这个注解包含了很多注解,也就是说使用这个注解可以少写几个注解,这里看源码粘出来一些,仅用于参考

正文:

/**
 * @SpringBootApplication组合注解包含以下注解:
 * 
 * @Target(ElementType.TYPE) :用于描述注解的使用范围
 * @Retention(RetentionPolicy.RUNTIME) :保留,指定保留时间,三个枚举,分别为source,class,runtime
 * @Documented:可被javadoc等工具记录,注解类型信息会保存到生成的文档中
 * @Inherited:个人认为是一个成员变量,父类被子类覆盖之后无法继承,子类中可以继承父类中未被覆盖的父类注解的值
 * @SpringBootConfiguration:包含@Target(ElementType.TYPE)
 *                                                     @Retention(RetentionPolicy.RUNTIME) :同上述
 *                                                     @Documented:同上述
 *                                                     @Configuration:用于配置,包含以下注解
 *                                                                                     @Target(ElementType.TYPE) :同上述
 *                                                                                     @Retention(RetentionPolicy.RUNTIME) :同上述
 *                                                                                     @Documented :同上述
 *                                                                                     @Component:spring内置组件注解,用途是让spring容器扫描
 * @EnableAutoConfiguration:开启自动配置,包含以下注解
 *                                                     @Target(ElementType.TYPE):同上述
 *                                                     @Retention(RetentionPolicy.RUNTIME):同上述
 *                                                     @Documented:同上述
 *                                                     @Inherited:同上述
 *                                                     @AutoConfigurationPackage:自动配置包含注解的类
 *                                                     @Import(AutoConfigurationImportSelector.class)
 * @ComponentScan:开启包扫描,默认扫描同级及当前包下内容,包含以下注解
 *                                         @Retention(RetentionPolicy.RUNTIME)
 *                                         @Target(ElementType.TYPE):同上述
 *                                         @Documented:同上述
 *                                         @Repeatable(ComponentScans.class):允许在同一申明类型(类,属性,或方法)的多次使用同一个注解
 */
@SpringBootApplication

这里有几个注解拆到后来还是可以继续拆分的,也就一两级,作用不是很大了,就不贴出来了,仅用于参考。

posted @ 2018-04-07 21:47  东北小狐狸  阅读(4946)  评论(0编辑  收藏  举报