Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

@AutoConfigurationPackage和@ComponentScan的作用有什么区别?

是关于@SpringBootApplication注解的一点疑惑,该注解的大致构成如下:image.png

其中@ComponentScan都知道是用于扫描主启动类路径及其子路径下的类,而@EnableAutoConfiguration中又有两个注解,其中@Import(AutoConfigurationImportSelector.class)是自动装载的关键,但我不知道另一个@AutoConfigurationPackage是干什么用的。
我在网上搜索看了很多文章都说@AutoConfigurationPackage的作用是在SpringBoot应用启动时默认会将启动类所在的package作为自动配置的package,但这件事不是@ComponentScan干的吗?难道@SpringBootApplication中这两个注解干的是同一件事?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@ComponentScan 是指定package,可以指定多个。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...