Update getting started documentation to use @SpringBootApplication

Closes gh-32795
This commit is contained in:
Phillip Webb 2022-10-18 20:44:28 -07:00 committed by Moritz Halbritter
parent d6f682da7e
commit 2cdd071775
4 changed files with 16 additions and 10 deletions

View File

@ -1016,4 +1016,7 @@ dependency-versions.coordinates=appendix.dependency-versions.coordinates
dependency-versions.properties=appendix.dependency-versions.properties
# gh-30405
web.servlet.spring-mvc.json=features.json.jackson.custom-serializers-and-deserializers
web.servlet.spring-mvc.json=features.json.jackson.custom-serializers-and-deserializers
# gh-32795
getting-started.first-application.code.enable-auto-configuration=getting-started.first-application.code.spring-boot-application

View File

@ -62,7 +62,7 @@ Open your favorite text editor and add the following:
<!-- Additional lines to be added here... -->
ifeval::["{spring-boot-artifactory-repo}" != "release"]
<!-- (you do not need this if you are using a .RELEASE version) -->
<!-- (you only need this if you are using a milestone or snapshot version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
@ -160,10 +160,13 @@ See the {spring-framework-docs}/web.html#mvc[MVC section] in the Spring Referenc
[[getting-started.first-application.code.enable-auto-configuration]]
==== The @EnableAutoConfiguration Annotation
The second class-level annotation is `@EnableAutoConfiguration`.
This annotation tells Spring Boot to "`guess`" how you want to configure Spring, based on the jar dependencies that you have added.
[[getting-started.first-application.code.spring-boot-application]]
==== The @SpringBootApplication Annotation
The second class-level annotation is `@SpringBootApplication`.
This annotation is known as a _meta-annotation_, it combines `@SpringBootConfiguration`, `@EnableAutoConfiguration` and `@ComponentScan`.
Of those, the annotation we're most interested in here is `@EnableAutoConfiguration`.
`@EnableAutoConfiguration` tells Spring Boot to "`guess`" how you want to configure Spring, based on the jar dependencies that you have added.
Since `spring-boot-starter-web` added Tomcat and Spring MVC, the auto-configuration assumes that you are developing a web application and sets up Spring accordingly.
.Starters and Auto-configuration

View File

@ -17,12 +17,12 @@
package org.springframework.boot.docs.gettingstarted.firstapplication.code;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
@SpringBootApplication
public class MyApplication {
@RequestMapping("/")

View File

@ -16,13 +16,13 @@
package org.springframework.boot.docs.gettingstarted.firstapplication.code
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@EnableAutoConfiguration
@SpringBootApplication
class MyApplication {
@RequestMapping("/")