简体   繁体   English

@SpringBootApplication如何在spring boot中实际工作?

[英]how does @SpringBootApplication actually work in spring boot?

I don't understand how the SpringBootApplication shortcut works. 我不明白SpringBootApplication快捷方式是如何工作的。 Specifically I don't understand how the individual sub annotations like @ComponentScan and @EnableAutoConfiguration get passed onto the actual application class as if they were written explicitly there. 具体来说,我不明白像@ComponentScan和@EnableAutoConfiguration这样的单个子注释如何传递到实际的应用程序类,就好像它们是在那里明确写出的一样。 I searched spring boot's code base for SpringBootApplication expecting to see code that looks for the "SpringBootApplication" string before applying these individual annotations but did not see any. 我搜索Spring Boot的SpringBootApplication代码库,期望在应用这些单独的注释之前看到代码查找“SpringBootApplication”字符串,但没有看到任何代码。 Can someone explain this? 有人可以解释一下吗? Thanks. 谢谢。

The @SpringBootApplication annotation is an annotation that is annotated with, among others, the annotations @ComponentScan and @EnableAutoConfiguration you mentioned. @SpringBootApplication注释是一个注释,其中注释了您提到的注释@ComponentScan@EnableAutoConfiguration Instead of scanning for @SpringBootApplication , Spring internally scans for these (implicit) annotations and does its magic accordingly. Spring不会扫描@SpringBootApplication ,而是在内部扫描这些(隐式)注释并相应地@SpringBootApplication其魔力。

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

And also Spring Boot reduces defining of Annotation configuration. 而且Spring Boot还减少了Annotation配置的定义。 If we use @SpringBootApplication annotation at class level, then Spring Boot AutoConfigurator will automatically add all required annotations to Java Class ByteCode. 如果我们在类级别使用@SpringBootApplication批注,那么Spring Boot AutoConfigurator会自动将所有必需的批注添加到Java Class ByteCode。

==> actually i can't find the code in spring boot autoconfig that does this. ==>实际上我找不到执行此操作的spring boot autoconfig中的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果没有@SpringBootApplication,Spring 启动应用程序如何工作? - How does Spring boot application works without @SpringBootApplication? Spring 的@Scheduled 是如何工作的? - How does Spring's @Scheduled actually work? 如何使用 JUnit 在没有 @SpringBootApplication 的情况下测试 Java Spring Boot 应用程序? - How to test Java Spring Boot application without @SpringBootApplication using JUnit? spring boot application中的@SpringBootApplication是在什么阶段执行的? - At what stage is @SpringBootApplication executed in spring boot application? Spring boot在@SpringBootApplication类上找不到默认构造函数 - Spring boot No default constructor found on @SpringBootApplication class Unabel在Spring Boot(Eclipse)中找到@EnableAutoConfiguration或@SpringBootApplication - Unabel to find @EnableAutoConfiguration or @SpringBootApplication in Spring boot (Eclipse) 池大小如何实际与Spring的计划任务一起使用? - How does pool size actually work with Spring's scheduled tasks? 如何使用@SpringBootApplication和@Configuration,数据源 - How to work with @SpringBootApplication and @Configuration, Datasource Spring IoC 如何在一个最小的例子中实际工作? - How does Spring IoC actually work in a minimal example? spring-boot @ConditionalOnClass 如何工作? - How does spring-boot @ConditionalOnClass work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM