@SpringBootApplication 注解由三个注解组成,分别为:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
1.@SpringBootConfiguration
与@Configuration功能一致,都是把当前类标注为配置类,并把该类中标注了@Bean注解的方法的实例加入到IoC容器中。
2.@EnableAutoConfiguration
字面意思为开启自动配置,即将的标注了@Configuration的配置类(符合一定条件的)加入到IoC容器中,大致原理为:
从ClassPath下扫描所有的META-INF/spring.factories配置文件,将配置文件中与EnableAutoConfiguration对应的配置项通过反射机制实例化为与之对应的标注了@Configuration的配置类,随后注入到IoC容器中。
3.@ComponentScan
@ComponentScan对应于XML配置形式中的<context:component-scan>,作用是将一些被特殊注解标注了的bean批量采集注入到IoC容器中,这些特殊注解主要包括:
@Service @Repository @Component @Controller @Entity
@SpringBootApplication是Spring Boot的核心注解,它整合了@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan。@SpringBootConfiguration相当于@Configuration,用于标记配置类。@EnableAutoConfiguration启动自动配置,从class path下的META-INF/spring.factories加载配置。@ComponentScan扫描@Component、@Service、@Repository和@Controller等注解的bean。这个注解简化了Spring应用的初始设置,实现了快速开发。
906

被折叠的 条评论
为什么被折叠?



