# 6.6. 使用@SpringBootApplication注解

许多 Spring Boot 开发人员喜欢他们的应用程序使用自动配置、组件扫描并能够在其“应用程序类”上定义额外的配置。可以使用单个`@SpringBootApplication`注释来启用这三个功能，即：

* `@EnableAutoConfiguration`：启用[Spring Boot的自动配置机制](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.auto-configuration)
* `@ComponentScan`：对应用程序所在的包启用`@Component`扫描（请参阅[最佳实践](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.structuring-your-code)）
* `@SpringBootConfiguration`：允许在上下文中注册额外的bean或导入额外的配置类。Spring 标准的`@Configuration`替代方案，有助于集成测试中的[配置检测。](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.testing.spring-boot-applications.detecting-configuration)

```
// Same as @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan
@SpringBootApplication
public class MyApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
​
}
```

> `@SpringBootApplication`还提供别名来自定义`@EnableAutoConfiguration`和`@ComponentScan`的属性。
>
> 这些功能都不是强制性的，您可以选择用它启用的任何功能来替换此单个注释。例如，您可能不想在应用程序中使用组件扫描或配置属性扫描：
>
> ```
> @SpringBootConfiguration(proxyBeanMethods = false)
> @EnableAutoConfiguration
> @Import({ SomeConfiguration.class, AnotherConfiguration.class })
> public class MyApplication {
> ​
>     public static void main(String[] args) {
>         SpringApplication.run(MyApplication.class, args);
>     }
> ​
> }
> ```
>
> 在此示例中，`MyApplication`与任何其他 Spring Boot 应用程序一样，只是不会自动检测`@Component`-annotated 类和`@ConfigurationProperties`-annotated 类，并且显式导入用户定义的 bean（请参阅 `@Import`参考资料）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.shiker.tech/spring-boot-can-kao-wen-dang/6.-shi-yong-spring-boot-jin-xing-kai-fa/6.6.-shi-yong-springbootapplication-zhu-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
