From 43a44006c95cac9bece9b3b917d63054aa83af82 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 18 Oct 2022 20:44:28 -0700 Subject: [PATCH] Update getting started documentation to use @SpringBootApplication Closes gh-32780 --- .../src/docs/asciidoc/anchor-rewrite.properties | 3 +++ .../asciidoc/getting-started/first-application.adoc | 13 ++++++++----- .../firstapplication/code/MyApplication.java | 4 ++-- .../firstapplication/code/MyApplication.kt | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties index 1bc8f29508..f92f3bd8a6 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties @@ -1008,3 +1008,6 @@ web.servlet.spring-mvc.json=features.json.jackson.custom-serializers-and-deseria # gh-28597 data.nosql.elasticsearch.connecting-using-rest.webclient=data.nosql.elasticsearch.connecting-using-rest.reactiveclient + +# Spring Boot 2.7 - 3.0 migrations +getting-started.first-application.code.enable-auto-configuration=getting-started.first-application.code.spring-boot-application diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc index 25464b3b33..8e2194570c 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc @@ -62,7 +62,7 @@ Open your favorite text editor and add the following: ifeval::["{spring-boot-artifactory-repo}" != "release"] - + spring-snapshots @@ -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 diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.java index c05e4abf45..62cabe70a6 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.java @@ -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("/") diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.kt index 798f5d3b50..a4ca07d621 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/gettingstarted/firstapplication/code/MyApplication.kt @@ -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("/")