Document @SpringBootApplication
Add a section to the reference guide about @SpringBootApplication. See gh-1842
This commit is contained in:
parent
e76a571dd3
commit
68571ee535
|
@ -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:
|
||||
|
||||
|
|
|
@ -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 <<using-boot-structuring-your-code, best practices>>
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue