Skip to content

Commit 6694f62

Browse files
authored
feat: update the Kotlin Spring Boot tutorial (#4796)
* update: update the Kotlin Spring Boot tutorial * update: update after the review, rollback the vars
1 parent a719522 commit 6694f62

14 files changed

+80
-63
lines changed
27.3 KB
Loading
125 KB
Loading
27.5 KB
Loading
123 KB
Loading
65 KB
Loading
-89.3 KB
Loading
50.8 KB
Loading

docs/kr.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<toc-element toc-title="Create a RESTful web service with a database using Spring Boot">
195195
<toc-element accepts-web-file-names="jvm-spring-boot-restful.html,spring-boot-restful.html,spring-boot-restful-db.html,jvm-spring-boot-restful-db.html" topic="jvm-get-started-spring-boot.md"/>
196196
<toc-element toc-title="Create a Spring Boot project" topic="jvm-create-project-with-spring-boot.md"/>
197-
<toc-element toc-title="Upgrade your project with data classes" topic="jvm-spring-boot-add-data-class.md"/>
197+
<toc-element topic="jvm-spring-boot-add-data-class.md"/>
198198
<toc-element topic="jvm-spring-boot-add-db-support.md"/>
199199
<toc-element toc-title="Use Spring Data CrudRepository" topic="jvm-spring-boot-using-crudrepository.md"/>
200200
</toc-element>

docs/topics/functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ reformat("This is a short String!", upperCaseFirstLetter = false, wordSeparator
141141
```
142142

143143
You can pass a [variable number of arguments (`vararg`)](#variable-number-of-arguments-varargs) with names using the
144-
`spread` operator:
144+
_spread_ operator (prefix the array with `*`):
145145

146146
```kotlin
147147
fun foo(vararg strings: String) { /*...*/ }
@@ -224,7 +224,7 @@ subsequent parameters must be passed using named argument syntax, or, if the par
224224
a lambda outside the parentheses.
225225

226226
When you call a `vararg`-function, you can pass arguments individually, for example `asList(1, 2, 3)`. If you already have
227-
an array and want to pass its contents to the function, use the *spread* operator (prefix the array with `*`):
227+
an array and want to pass its contents to the function, use the spread operator (prefix the array with `*`):
228228

229229
```kotlin
230230
val a = arrayOf(1, 2, 3)

docs/topics/jvm/jvm-create-project-with-spring-boot.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
<p><img src="icon-1.svg" width="20" alt="First step"/> <strong>Create a Spring Boot project with Kotlin</strong><br/><img src="icon-2-todo.svg" width="20" alt="Second step"/> Add a data class to the Spring Boot project<br/><img src="icon-3-todo.svg" width="20" alt="Third step"/> Add database support for the Spring Boot project<br/><img src="icon-4-todo.svg" width="20" alt="Fourth step"/> Use Spring Data CrudRepository for database access<br/></p>
77
</tldr>
88

9-
The first part of the tutorial shows you how to create a Spring Boot project in IntelliJ IDEA using Project Wizard.
9+
The first part of the tutorial shows how to create a Spring Boot project with Gradle in IntelliJ IDEA using the Project Wizard.
10+
11+
> This tutorial doesn't require using Gradle as the build system. You can follow the same steps if you use Maven.
12+
>
13+
{style="note"}
1014

1115
## Before you start
1216

1317
Download and install the latest version of [IntelliJ IDEA Ultimate Edition](https://www.jetbrains.com/idea/download/index.html).
1418

15-
> If you use IntelliJ IDEA Community Edition or another IDE, you can generate a Spring Boot project using a [web-based project generator](https://start.spring.io).
19+
> If you use IntelliJ IDEA Community Edition or another IDE, you can generate a Spring Boot project using
20+
> a [web-based project generator](https://start.spring.io/#!language=kotlin&type=gradle-project-kotlin).
1621
>
17-
{style="note"}
22+
{style="tip"}
1823

1924
## Create a Spring Boot project
2025

2126
Create a new Spring Boot project with Kotlin by using the Project Wizard in IntelliJ IDEA Ultimate Edition:
2227

23-
> You can also create a new project using [IntelliJ IDEA with the Spring Boot plugin](https://www.jetbrains.com/help/idea/spring-boot.html).
24-
>
25-
{style="note"}
26-
2728
1. In IntelliJ IDEA, select **File** | **New** | **Project**.
2829
2. In the panel on the left, select **New Project** | **Spring Boot**.
29-
3. Specify the following fields and options in the Project Wizard window:
30+
3. Specify the following fields and options in the **New Project** window:
3031

3132
* **Name**: demo
3233
* **Language**: Kotlin
@@ -36,10 +37,10 @@ Create a new Spring Boot project with Kotlin by using the Project Wizard in Inte
3637
>
3738
{style="tip"}
3839

39-
* **Package name**: demo
40+
* **Package name**: com.example.demo
4041
* **JDK**: Java JDK
4142

42-
> This tutorial uses **Amazon Corretto version 21**.
43+
> This tutorial uses **Amazon Corretto version 23**.
4344
> If you don't have a JDK installed, you can download it from the dropdown list.
4445
>
4546
{style="note"}
@@ -83,10 +84,10 @@ Here is the full script with the explanation of all parts and dependencies:
8384
```kotlin
8485
// build.gradle.kts
8586
plugins {
86-
kotlin("jvm") version "1.9.24" // The version of Kotlin to use
87-
kotlin("plugin.spring") version "1.9.24" // The Kotlin Spring plugin
88-
id("org.springframework.boot") version "3.3.4"
89-
id("io.spring.dependency-management") version "1.1.6"
87+
kotlin("jvm") version "%springBootSupportedKotlinVersion%" // The version of Kotlin to use
88+
kotlin("plugin.spring") version "%springBootSupportedKotlinVersion%" // The Kotlin Spring plugin
89+
id("org.springframework.boot") version "%springBootVersion%"
90+
id("io.spring.dependency-management") version "1.1.7"
9091
}
9192

9293
group = "com.example"
@@ -139,13 +140,15 @@ As you can see, there are a few Kotlin-related artifacts added to the Gradle bui
139140
3. After the dependencies section, you can see the `kotlin` plugin configuration block.
140141
This is where you can add extra arguments to the compiler to enable or disable various language features.
141142

143+
Learn more about the Kotlin compiler options in [](gradle-compiler-options.md).
144+
142145
## Explore the generated Spring Boot application
143146

144147
Open the `DemoApplication.kt` file:
145148

146149
```kotlin
147150
// DemoApplication.kt
148-
package demo
151+
package com.example.demo
149152

150153
import org.springframework.boot.autoconfigure.SpringBootApplication
151154
import org.springframework.boot.runApplication
@@ -190,12 +193,12 @@ fun main(args: Array<String>) {
190193
The application is ready to run, but let's update its logic first.
191194

192195
In the Spring application, a controller is used to handle the web requests.
193-
In the same package with `DemoApplication.kt` file, create the `MessageController.kt` file with the
196+
In the same package, next to the `DemoApplication.kt` file, create the `MessageController.kt` file with the
194197
`MessageController` class as follows:
195198

196199
```kotlin
197200
// MessageController.kt
198-
package demo
201+
package com.example.demo
199202

200203
import org.springframework.web.bind.annotation.GetMapping
201204
import org.springframework.web.bind.annotation.RequestParam
@@ -243,7 +246,7 @@ class MessageController {
243246

244247
The Spring application is now ready to run:
245248

246-
1. Click the green Run icon in the gutter beside the `main()` method:
249+
1. In the `DemoApplication.kt` file, click the green **Run** icon in the gutter beside the `main()` method:
247250

248251
![Run Spring Boot application](run-spring-boot-application.png){width=706}
249252

0 commit comments

Comments
 (0)