diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 53af236f843..e895280b822 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1442,7 +1442,7 @@ and http://hibernate.org/orm/documentation/[Hibernate] reference documentation. Traditionally, JPA '`Entity`' classes are specified in a `persistence.xml` file. With Spring Boot this file is not necessary and instead '`Entity Scanning`' is used. By default all packages below your main configuration class (the one annotated with -`@EnableAutoConfiguration`) will be searched. +`@EnableAutoConfiguration` or `@SpringBootApplication`) will be searched. Any classes annotated with `@Entity`, `@Embeddable` or `@MappedSuperclass` will be considered. A typical entity class would look something like this: @@ -1511,7 +1511,8 @@ Spring Data repositories usually extend from the {spring-data-commons-javadoc}/repository/Repository.html[`Repository`] or {spring-data-commons-javadoc}/repository/CrudRepository.html[`CrudRepository`] interfaces. If you are using auto-configuration, repositories will be searched from the package containing your -main configuration class (the one annotated with `@EnableAutoConfiguration`) down. +main configuration class (the one annotated with `@EnableAutoConfiguration` or +`@SpringBootApplication`) down. Here is a typical Spring Data repository: diff --git a/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc b/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc index afbb23b63d0..0ef74468620 100644 --- a/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc +++ b/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc @@ -550,6 +550,36 @@ as `final`, indicating that it cannot be subsequently changed. +[[using-boot-using-springbootapplication-annotation]] +== Using the @SpringBootApplication annotation +Many Spring Boot developers always have their main class annotated with `@Configuration`, +`@EnableAutoConfiguration` and `@ComponentScan`. Since these annotations are so frequently +used together (especially if you follow the <> +above), Spring Boot provides a convenient `@SpringBootApplication` alternative. + +The `@SpringBootApplication` annotation is equivalent to using `@Configuration`, +`@EnableAutoConfiguration` and `@ComponentScan` with their default attributes: + + +[source,java,indent=0] +---- + package com.example.myproject; + + import org.springframework.boot.SpringApplication; + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan + public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + } +---- + + + [[using-boot-running-your-application]] == Running your application One of the biggest advantages of packaging your application as jar and using an embedded