Skip to content

Commit ac54210

Browse files
authored
update: Spring Boot ver 4.0.2 (#5290)
1 parent d3b0267 commit ac54210

14 files changed

+42
-391
lines changed
-6.84 KB
Loading
-24.5 KB
Loading
-62.2 KB
Loading
-132 KB
Loading
-89.5 KB
Loading
20.2 KB
Loading
101 KB
Loading
4.36 KB
Loading

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Download and install the latest version of [IntelliJ IDEA Ultimate Edition](http
2727
Create a new Spring Boot project with Kotlin by using the Project Wizard in IntelliJ IDEA Ultimate Edition:
2828

2929
1. In IntelliJ IDEA, select **File** | **New** | **Project**.
30-
2. In the panel on the left, select **New Project** | **Spring Boot**.
30+
2. In the panel on the left, select **Spring Boot** in the **Generators** section.
3131
3. Specify the following fields and options in the **New Project** window:
3232

3333
* **Name**: demo
@@ -52,7 +52,7 @@ Create a new Spring Boot project with Kotlin by using the Project Wizard in Inte
5252
>
5353
{style="tip"}
5454

55-
![Create Spring Boot project](create-spring-boot-project.png){width=800}
55+
![Create Spring Boot project](create-spring-boot-project.png){width=700}
5656

5757
4. Ensure that you have specified all the fields and click **Next**.
5858

@@ -62,7 +62,7 @@ Create a new Spring Boot project with Kotlin by using the Project Wizard in Inte
6262
* **SQL | Spring Data JDBC**
6363
* **SQL | H2 Database**
6464

65-
![Set up Spring Boot project](set-up-spring-boot-project.png){width=800}
65+
![Set up Spring Boot project](set-up-spring-boot-project.png){width=700}
6666

6767
6. Click **Create** to generate and set up the project.
6868

@@ -109,19 +109,21 @@ repositories {
109109
}
110110

111111
dependencies {
112+
implementation("org.springframework.boot:spring-boot-h2console")
112113
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
113-
implementation("org.springframework.boot:spring-boot-starter-web")
114-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") // Jackson extensions for Kotlin for working with JSON
114+
implementation("org.springframework.boot:spring-boot-starter-webmvc")
115115
implementation("org.jetbrains.kotlin:kotlin-reflect") // Kotlin reflection library, required for working with Spring
116+
implementation("tools.jackson.module:jackson-module-kotlin") // Jackson extensions for Kotlin for working with JSON
116117
runtimeOnly("com.h2database:h2")
117-
testImplementation("org.springframework.boot:spring-boot-starter-test")
118+
testImplementation("org.springframework.boot:spring-boot-starter-data-jdbc-test")
119+
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
118120
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
119121
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
120122
}
121123

122124
kotlin {
123125
compilerOptions {
124-
freeCompilerArgs.addAll("-Xjsr305=strict") // `-Xjsr305=strict` enables the strict mode for JSR-305 annotations
126+
freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property") // `-Xjsr305=strict` enables the strict mode for JSR-305 annotations
125127
}
126128
}
127129

@@ -134,13 +136,15 @@ As you can see, there are a few Kotlin-related artifacts added to the Gradle bui
134136

135137
1. In the `plugins` block, there are two Kotlin artifacts:
136138

137-
* `kotlin("jvm")` – the plugin defines the version of Kotlin to be used in the project
138-
* `kotlin("plugin.spring")` – Kotlin Spring compiler plugin for adding the `open` modifier to Kotlin classes in order to make them compatible with Spring Framework features
139+
* The `kotlin("jvm")` plugin defines the version of Kotlin to be used in the project.
140+
* The Kotlin Spring compiler plugin, `kotlin("plugin.spring")`, adds the `open` modifier to Kotlin classes to make
141+
them compatible with Spring Framework features
139142

140-
2. In the `dependencies` block, a few Kotlin-related modules listed:
143+
2. In the `dependencies` block, a few Kotlin-related modules are listed:
141144

142-
* `com.fasterxml.jackson.module:jackson-module-kotlin` – the module adds support for serialization and deserialization of Kotlin classes and data classes
143-
* `org.jetbrains.kotlin:kotlin-reflect` – Kotlin reflection library
145+
* The `tools.jackson.module:jackson-module-kotlin` module adds support for serialization and deserialization of Kotlin
146+
classes and data classes.
147+
* `org.jetbrains.kotlin:kotlin-reflect` is a Kotlin reflection library that enables full support of the [reflection features](reflection.md).
144148

145149
3. After the dependencies section, you can see the `kotlin` plugin configuration block.
146150
This is where you can add extra arguments to the compiler to enable or disable various language features.
@@ -172,8 +176,8 @@ fun main(args: Array<String>) {
172176
<p>In Kotlin, if a class doesn't include any members (properties or functions), you can omit the class body (<code>{}</code>) for good.</p>
173177
</def>
174178
<def title="@SpringBootApplication annotation">
175-
<p><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.using-the-springbootapplication-annotation"><code>@SpringBootApplication annotation</code></a> is a convenience annotation in a Spring Boot application.
176-
It enables Spring Boot's <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration">auto-configuration</a>, <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html">component scan</a>, and be able to define an extra configuration on their "application class".
179+
<p><a href="https://docs.spring.io/spring-boot/reference/using/using-the-springbootapplication-annotation.html#using.using-the-springbootapplication-annotation"><code>@SpringBootApplication annotation</code></a> is a convenience annotation in a Spring Boot application.
180+
It enables Spring Boot's <a href="https://docs.spring.io/spring-boot/reference/using/auto-configuration.html#using.auto-configuration">auto-configuration</a>, <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html">component scan</a>, and be able to define an extra configuration on their "application class".
177181
</p>
178182
</def>
179183
<def title="Program entry point – main()">
@@ -192,7 +196,6 @@ fun main(args: Array<String>) {
192196
</def>
193197
</deflist>
194198

195-
196199
## Create a controller
197200

198201
The application is ready to run, but let's update its logic first.
@@ -253,7 +256,7 @@ The Spring application is now ready to run:
253256

254257
1. In the `DemoApplication.kt` file, click the green **Run** icon in the gutter beside the `main()` method:
255258

256-
![Run Spring Boot application](run-spring-boot-application.png){width=706}
259+
![Run Spring Boot application](run-spring-boot-application.png){width=700}
257260

258261
> You can also run the `./gradlew bootRun` command in the terminal.
259262
>
@@ -269,7 +272,7 @@ The Spring application is now ready to run:
269272
270273
You should see "Hello, John!" printed as a response:
271274
272-
![Spring Application response](spring-application-response.png){width=706}
275+
![Spring Application response](spring-application-response.png){width=700}
273276
274277
## Next step
275278

docs/topics/jvm/jvm-spring-boot-add-data-class.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ It requires changing the `MessageController` class to respond with a JSON docume
8484
</list>
8585
<p>The corresponding factory functions are also provided by the Kotlin Standard Library to create instances of such collections.
8686
</p>
87-
<p>In this tutorial, you use the <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/list-of.html"><code>listOf()</code></a> function to create a list of <code>Message</code> objects.
87+
<p>In this tutorial, you use the <a href="https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/list-of.html"><code>listOf()</code></a> function to create a list of <code>Message</code> objects.
8888
This is the factory function to create a <i>read-only</i> list of objects: you can't add or remove elements from the list.<br/>
89-
If it is required to perform write operations on the list, call the <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/mutable-list-of.html"><code>mutableListOf()</code></a> function to create a mutable list instance.
89+
If it is required to perform write operations on the list, call the <a href="https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/mutable-list-of.html"><code>mutableListOf()</code></a> function to create a mutable list instance.
9090
</p>
9191
</def>
9292
<def title="Trailing comma">
@@ -102,8 +102,8 @@ It requires changing the `MessageController` class to respond with a JSON docume
102102
103103
The response from `MessageController` will now be a JSON document containing a collection of `Message` objects.
104104
105-
> Any controller in the Spring application renders JSON response by default if Jackson library is on the classpath.
106-
> As you [specified the `spring-boot-starter-web` dependency in the `build.gradle.kts` file](jvm-create-project-with-spring-boot.md#explore-the-project-gradle-build-file), you received Jackson as a _transitive_ dependency.
105+
> Any controller in the Spring application renders a JSON response by default if the Jackson library is on the classpath.
106+
> As you [specified the `spring-boot-starter-webmvc` dependency in the `build.gradle.kts` file](jvm-create-project-with-spring-boot.md#explore-the-project-gradle-build-file), you received Jackson as a _transitive_ dependency.
107107
> Hence, the application responds with a JSON document if the endpoint returns a data structure that can be serialized to JSON.
108108
>
109109
{style="note"}
@@ -169,10 +169,10 @@ The Spring application is ready to run:
169169
170170
You will see a page with a collection of messages in JSON format:
171171
172-
![Run the application](messages-in-json-format.png){width=800}
172+
![Run the application](messages-in-json-format.png){width=700}
173173
174174
## Next step
175175
176-
In the next part of the tutorial, you'll add and configure a database to your project, and make HTTP requests.
176+
In the next part of the tutorial, you'll add and configure a database to your project and make HTTP requests.
177177

178178
**[Proceed to the next chapter](jvm-spring-boot-add-db-support.md)**

0 commit comments

Comments
 (0)