You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most Spring Boot applications use the `spring-boot-starter-parent` in the `parent` section of the POM.
103
174
The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults.
104
175
It also provides a <<using#using.build-systems.dependency-management,`dependency-management`>> section so that you can omit `version` tags for "`blessed`" dependencies.
105
176
106
-
Other "`Starters`" provide dependencies that you are likely to need when developing a specific type of application.
107
177
Since we are developing a web application, we add a `spring-boot-starter-web` dependency.
108
178
Before that, we can look at what we currently have by running the following command:
109
179
@@ -130,12 +200,45 @@ To add the necessary dependencies, edit your `pom.xml` and add the `spring-boot-
130
200
131
201
If you run `mvn dependency:tree` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
Most Spring Boot applications use the `org.springframework.boot` Gradle plugin.
207
+
This plugin provides useful defaults and Gradle tasks.
208
+
The `io.spring.dependency-management` Gradle plugin provides <<using#using.build-systems.dependency-management, dependency management>> so that you can omit `version` tags for "`blessed`" dependencies.
209
+
210
+
Since we are developing a web application, we add a `spring-boot-starter-web` dependency.
211
+
Before that, we can look at what we currently have by running the following command:
If you run `gradle dependencies` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
133
236
134
237
135
238
[[getting-started.first-application.code]]
136
239
=== Writing the Code
137
240
To finish our application, we need to create a single Java file.
138
-
By default, Maven compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/MyApplication.java` to contain the following code:
241
+
By default, Maven and Gradle compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/MyApplication.java` to contain the following code:
139
242
140
243
include::code:MyApplication[]
141
244
@@ -191,6 +294,9 @@ The `args` array is also passed through to expose any command-line arguments.
191
294
192
295
[[getting-started.first-application.run]]
193
296
=== Running the Example
297
+
298
+
[[getting-started.first-application.run.maven]]
299
+
==== Maven
194
300
At this point, your application should work.
195
301
Since you used the `spring-boot-starter-parent` POM, you have a useful `run` goal that you can use to start the application.
196
302
Type `mvn spring-boot:run` from the root project directory to start the application.
@@ -222,6 +328,39 @@ If you open a web browser to `http://localhost:8080`, you should see the followi
222
328
223
329
To gracefully exit the application, press `ctrl-c`.
224
330
331
+
[[getting-started.first-application.run.gradle]]
332
+
==== Gradle
333
+
334
+
At this point, your application should work.
335
+
Since you used the `org.springframework.boot` Gradle plugin, you have a useful `bootRun` goal that you can use to start the application.
336
+
Type `gradle bootRun` from the root project directory to start the application.
0 commit comments