SpringBoot之@ComponentScan和@SpringBootApplication扫描覆盖问题

时间:2021-04-30 11:56:23   收藏:0   阅读:0

@SpringBootApplication=@Configuration+@EnableAutoConfiguration+@ComponentScan,其中扫描包的范围为启动类所在包和子包,不包括第三方的jar包。如果我们需要扫描通过maven依赖添加的jar,我们就要单独使用@ComponentScan注解扫描第三方包。
但是,如果@SpringBootApplication和@ComponentScan注解共存,那么@SpringBootApplication注解的扫描的作用将会失效,也就是说不能够扫描启动类所在包以及子包了
使用
@ComponentScans({
@ComponentScan("包名"),
@ComponentScan("com.immortal.springcloudapi")
})

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!