springboot @SpringBootApplication注解

springboot 提供了@SpringBootApplication注解,用来标注是springboot启动项目,该注解为合成注解,即@SpringBootApplication=@SpringBootConfiguration+@EnableAutoConfiguration+@ComponentScan三个注解。
官网给出的定义:
Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their “application class”. A single @SpringBootApplication annotation can be used to enable those three features, that is:
@EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism
@ComponentScan: enable @Component scan on the package where the application is located (see the best practices)
@SpringBootConfiguration: enable registration of extra beans in the context or the import of additional configuration classes.
An alternative to Spring’s standard @Configuration that aids configuration detection in your integration tests.

许多的springboot开发者喜欢在他们的应用类中去使用auto-configuration、auto-configuration scan 和能够定义一些额外的配置,一个@SpringBootApplication注解能够包含三个特征,分别是:
@EnableAutoConfiguration:能够开启springboot的自动配置机制
@ComponentScan: 能够扫描应用所在的包
@SpringBootConfiguration:能够在上下文中注册额外的类或者引入添加的配置类
Spring 标准 @Configuration 的替代方案,可帮助您在集成测试中进行配置检测

默认情况下,扫描范围为启动类所在包下的范围,例如
在这里插入图片描述
图片中的MyApplication 使用了@SpringBootApplication注解后,扫描范围是:com.lixl.demo.application但是不会扫描com.lixl.demo.other包。
同时springboot也提供了解决办法:使用@ComponentScan注解进行扫描范围设置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值