Upgrade to Spring Boot 2.2.1

This commit is contained in:
Sébastien Deleuze
2019-11-19 12:41:58 +01:00
parent 8d2b2f5098
commit e59339fa10
5 changed files with 18 additions and 23 deletions

View File

@@ -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
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<!-- See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
<dependency>
@@ -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

View File

@@ -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") {

View File

@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@@ -56,11 +56,9 @@
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<!-- See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
<dependency>

View File

@@ -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<String>) {

View File

@@ -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