Upgrade to Spring Boot 2.2.1
This commit is contained in:
30
README.adoc
30
README.adoc
@@ -131,7 +131,7 @@ dependencies {
|
|||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
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")
|
runtimeOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
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>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.4.200</version>
|
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<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.
|
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`
|
`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.
|
Restart the web application, refresh `http://localhost:8080/`, you should see the banner on the blog homepage.
|
||||||
|
|
||||||
== Conclusion
|
== Conclusion
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("plugin.jpa") version "1.3.50"
|
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"
|
id("io.spring.dependency-management") version "1.0.8.RELEASE"
|
||||||
kotlin("jvm") version "1.3.50"
|
kotlin("jvm") version "1.3.50"
|
||||||
kotlin("plugin.spring") 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("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
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")
|
runtimeOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
kapt("org.springframework.boot:spring-boot-configuration-processor")
|
kapt("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -14,7 +14,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.2.0.RELEASE</version>
|
<version>2.2.1.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -56,11 +56,9 @@
|
|||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- See https://github.com/spring-projects/spring-boot/issues/18593 and https://github.com/h2database/h2database/issues/1841 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.4.200</version>
|
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.example.blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableConfigurationProperties(BlogProperties::class)
|
||||||
class BlogApplication
|
class BlogApplication
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import org.springframework.http.MediaType
|
|||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||||
|
|
||||||
@WebMvcTest
|
@WebMvcTest
|
||||||
@EnableConfigurationProperties(BlogProperties::class)
|
|
||||||
class HttpControllersTests(@Autowired val mockMvc: MockMvc) {
|
class HttpControllersTests(@Autowired val mockMvc: MockMvc) {
|
||||||
|
|
||||||
@MockkBean
|
@MockkBean
|
||||||
|
|||||||
Reference in New Issue
Block a user