springboot学习总结(二)关于@SpringBootApplication的一些基础知识点 | 您所在的位置:网站首页 › 安卓的知识点总结 › springboot学习总结(二)关于@SpringBootApplication的一些基础知识点 |
1、@SpringBootApplication
它是一个复合Annotation,实际上对于SpringBoot应用来说,最重要的是只有三个 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited// 最重要的三个 @Configuration @EnableAutoConfiguration @ComponentScanpublic @interface SpringBootApplication{ ... }
每次写三个Annotation过于繁琐 @Configuration @EnableAutoConfiguration @ComponentScan public class DemoApplication { public static void main(String[] args) { SpringApplication.run(SpringBoot01Application.class, args); } }可以简化,写一个@SpringBootApplication一站式复合 @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(SpringBoot01Application.class, args); } }
2、@ComponentScan 功能:自动扫描并加载符合条件的组件或bean定义,然后加载到容器中
3、@EnableAutoConfiguration,也是一个复合Annotation @Target(ElementType.TYPE) @Retention(RententionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import(EnableAutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration{ ... }最关键的是@Import,将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IoC容器。 借助Spring框架原有的工具类SpringFactoriesLoader的支持,@EnableAutoConfiguration才能实现"智能"的自动化配置。
-- End --待续~
|
CopyRight 2018-2019 实验室设备网 版权所有 |