Spring Boot 扫描的问题

174 阅读1分钟

@SpringBootApplication=@Configuration+@EnableAutoConfiguration+@ComponentScan,其中扫描包的范围为启动类所在包和子包,不包括第三方的jar包。如果我们需要扫描通过maven依赖添加的jar,我们就要单独使用@ComponentScan注解扫描第三方包。如果@SpringBootApplication和@ComponentScan共存,那么启动类就默认扫描不到启动类所在包以及子包了,需要手动来添加到@ComponentScan中去