提问者:小点点

@SpringBootApplication如何在Spring启动中实际工作?


我不明白SpringBootApplication快捷方式是如何工作的。具体来说,我不明白像@ComponentScan和@EnableAutoConfiguration这样的单独子注释是如何被传递到实际的应用程序类中的,就好像它们是在那里显式编写的一样。我搜索了Spring boot的SpringBootApplication代码库,希望在应用这些单独的注释之前看到查找“SpringBootApplication”字符串的代码,但没有看到任何代码。有人能解释一下吗?谢谢。


共2个答案

匿名用户

@SpringBootApplication注释是一个注释,其中包括您提到的注释@ComponentScan@EnableAutoConfiguration。Spring不是扫描@SpringBootApplication,而是在内部扫描这些(隐式)注释并相应地发挥其魔力。

匿名用户

http://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework

如果我们在类级别使用@SpringBootApplication注解,那么Spring Boot AutoConfigurator会自动将所有需要的注解添加到JavaClass ByteCode中。

==