1、@SpringBootApplication注解
@SpringBootApplication是一个复合注解,包括
@ComponentScan
@SpringBootConfiguration
@EnableAutoConfiguration。
@SpringBootConfiguration,继承自@Configuration,二者功能也一致,标注当前类是配置类,并会将当前类内声明的一个或多个以@Bean注解标记的方法的实例纳入到Spring容器中,并且实例名就是方法名。
@EnableAutoConfiguration,其作用启动自动配置,
@EnableAutoConfiguration,注解意思就是Springboot根据你添加的jar包来配置你项目的默认配置,比如根据spring-boot-starter-web ,来判断你的项目是否需要添加了webmvc和tomcat,就会自动的帮你配置web项目中所需要的默认配置。
@ComponentScan,扫描当前包及其子包下被@Component,@Controller,@Service,@Repository注解标记的类并纳入到spring容器中进行管理。是以前的<context:component-scan>(以前使用在xml中使用的标签,用来扫描包配置的平行支持)。
@SpringBootApplication只会扫描@SpringBootApplication注解标记类包下及其子包的类(特定注解标记,比如@Controller,@Service,@Component,@Configuration和@Bean注解等等)
Spring Boot中一些注解的使用
最新推荐文章于 2022-09-11 13:11:25 发布
1、@SpringBootApplication注解@SpringBootApplication是一个复合注解,包括@ComponentScan@SpringBootConfiguration@EnableAutoConfiguration。@SpringBootConfiguration,继承自@Configuration,二者功能也一致,标注当前类是配置类,并会将当前类内...
摘要由CSDN通过智能技术生成