Update getting started documentation to use @SpringBootApplication
Closes gh-32780
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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("/")
|
||||
|
||||
@@ -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("/")
|
||||
|
||||
Reference in New Issue
Block a user