From e59339fa1084a368cf0c6658586a1201cfdf60cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 19 Nov 2019 12:41:58 +0100 Subject: [PATCH] Upgrade to Spring Boot 2.2.1 --- README.adoc | 30 ++++++++----------- build.gradle.kts | 4 +-- pom.xml | 4 +-- .../com/example/blog/BlogApplication.kt | 2 ++ .../com/example/blog/HttpControllersTests.kt | 1 - 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/README.adoc b/README.adoc index 54a4d90..7ddb9dd 100644 --- a/README.adoc +++ b/README.adoc @@ -131,7 +131,7 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - runtimeOnly("com.h2database:h2:1.4.200") // See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 + runtimeOnly("com.h2database:h2") runtimeOnly("org.springframework.boot:spring-boot-devtools") testImplementation("org.springframework.boot:spring-boot-starter-test") } @@ -243,11 +243,9 @@ Notice also that Kotlin compiler is configured to generate Java 8 bytecode (Java spring-boot-devtools runtime - com.h2database h2 - 1.4.200 runtime @@ -895,6 +893,18 @@ data class BlogProperties(var title: String, val banner: Banner) { } ---- +Then we enable it at `BlogApplication` level. + +`src/main/kotlin/com/example/blog/BlogApplication.kt` +[source,kotlin] +---- +@SpringBootApplication +@EnableConfigurationProperties(BlogProperties::class) +class BlogApplication { + // ... +} +---- + To generate https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#configuration-metadata-annotation-processor[your own metadata] in order to get these custom properties recognized by your IDE, https://kotlinlang.org/docs/reference/kapt.html[kapt should be configured] with the `spring-boot-configuration-processor` dependency as following. `build.gradle.kts` @@ -974,20 +984,6 @@ class HtmlController(private val repository: ArticleRepository, // ... ---- -Since `@ConfigurationProperties` are not scanned automatically in test slices, we need to configure it explicitly in our -test annotated with `@WebMvcTest`. - -`src/main/kotlin/com/example/blog/BlogApplication.kt` -[source,kotlin] ----- -@WebMvcTest -@EnableConfigurationProperties(BlogProperties::class) -class HttpControllersTests(@Autowired val mockMvc: MockMvc) { - // ... -} ----- - - Restart the web application, refresh `http://localhost:8080/`, you should see the banner on the blog homepage. == Conclusion diff --git a/build.gradle.kts b/build.gradle.kts index 134857b..bfbebb4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("plugin.jpa") version "1.3.50" - id("org.springframework.boot") version "2.2.0.RELEASE" + id("org.springframework.boot") version "2.2.1.RELEASE" id("io.spring.dependency-management") version "1.0.8.RELEASE" kotlin("jvm") version "1.3.50" kotlin("plugin.spring") version "1.3.50" @@ -25,7 +25,7 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - runtimeOnly("com.h2database:h2:1.4.200") // See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 + runtimeOnly("com.h2database:h2") runtimeOnly("org.springframework.boot:spring-boot-devtools") kapt("org.springframework.boot:spring-boot-configuration-processor") testImplementation("org.springframework.boot:spring-boot-starter-test") { diff --git a/pom.xml b/pom.xml index 337dab5..a8aa0a5 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.2.0.RELEASE + 2.2.1.RELEASE @@ -56,11 +56,9 @@ spring-boot-devtools runtime - com.h2database h2 - 1.4.200 runtime diff --git a/src/main/kotlin/com/example/blog/BlogApplication.kt b/src/main/kotlin/com/example/blog/BlogApplication.kt index fba625f..e9f7593 100644 --- a/src/main/kotlin/com/example/blog/BlogApplication.kt +++ b/src/main/kotlin/com/example/blog/BlogApplication.kt @@ -1,9 +1,11 @@ package com.example.blog import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.runApplication @SpringBootApplication +@EnableConfigurationProperties(BlogProperties::class) class BlogApplication fun main(args: Array) { diff --git a/src/test/kotlin/com/example/blog/HttpControllersTests.kt b/src/test/kotlin/com/example/blog/HttpControllersTests.kt index c304b46..ff2daca 100644 --- a/src/test/kotlin/com/example/blog/HttpControllersTests.kt +++ b/src/test/kotlin/com/example/blog/HttpControllersTests.kt @@ -12,7 +12,6 @@ import org.springframework.http.MediaType import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* @WebMvcTest -@EnableConfigurationProperties(BlogProperties::class) class HttpControllersTests(@Autowired val mockMvc: MockMvc) { @MockkBean