SpringBoot核心注解@SpringBootApplication一二

SpringBoot核心注解@SpringBootApplication,用于SpringBoot项目的启动类上,在2.2.x版本中是4个注解的组合,即

@SpringBootConfiguration

@EnableAutoConfiguration

@ComponentScan

@ConfigurationPropertiesScan

@SpringBootConfiguration是对@Configuration注解的封装,可以结合@Bean,@ImportResource,@Import注解使用,起到替代Spring项目中applicationContext.xml配置文件的作用。

@ComponentScan开启注解扫描,通过basePackages属性指定一个或多个包路径。

@EnableAutoConfiguration实际是通过@Import引入了AutoConfigurationImportSelector类,实现了ImportSelector接口和selectImports方法,用于从META-INFO目录下的spring.factories文件中加载自动配置类,返回符合条件的自动配置类。

@ConfigurationPropertiesScan从2.2.0版本引入,通过@Import注解引入ConfigurationPropertiesScanRegistrar类,用于扫描@ConfigurationProperties注解的类,通过basePackages,value,basePackageClasses指定要扫描的包路径。

 
 

猜你喜欢

转载自blog.csdn.net/suoyx/article/details/109016077
今日推荐