spring-boot/spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/using-the-springbootapplication-annotation.adoc
Phillip Webb 0e906dc6e2 Use convention based code imports
Closes gh-29647
2022-02-04 19:46:44 -08:00

24 lines
1.7 KiB
Plaintext

[[using.using-the-springbootapplication-annotation]]
== Using the @SpringBootApplication Annotation
Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their "application class".
A single `@SpringBootApplication` annotation can be used to enable those three features, that is:
* `@EnableAutoConfiguration`: enable <<using#using.auto-configuration,Spring Boot's auto-configuration mechanism>>
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using#using.structuring-your-code,the best practices>>)
* `@SpringBootConfiguration`: enable registration of extra beans in the context or the import of additional configuration classes.
An alternative to Spring's standard `@Configuration` that aids <<features#features.testing.spring-boot-applications.detecting-configuration,configuration detection>> in your integration tests.
include::code:springapplication/MyApplication[]
NOTE: `@SpringBootApplication` also provides aliases to customize the attributes of `@EnableAutoConfiguration` and `@ComponentScan`.
[NOTE]
====
None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables.
For instance, you may not want to use component scan or configuration properties scan in your application:
include::code:individualannotations/MyApplication[]
In this example, `MyApplication` is just like any other Spring Boot application except that `@Component`-annotated classes and `@ConfigurationProperties`-annotated classes are not detected automatically and the user-defined beans are imported explicitly (see `@Import`).
====