Skip to content

Commit d106d3f

Browse files
Refactor spring-boot-kotlin-redis example to be more Kotlin idiomatic (#7185)
Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent 9220816 commit d106d3f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
13
plugins {
24
id("org.springframework.boot") version "2.7.10"
3-
id("org.jetbrains.kotlin.jvm") version "1.8.10"
4-
id("org.jetbrains.kotlin.plugin.spring") version "1.8.20"
5+
kotlin("jvm") version "1.8.10"
6+
kotlin("plugin.spring") version "1.8.20"
57
}
68

7-
apply plugin: 'io.spring.dependency-management'
9+
java.sourceCompatibility = JavaVersion.VERSION_1_8
810

911
repositories {
1012
mavenCentral()
1113
}
1214

1315
dependencies {
16+
apply(plugin = "io.spring.dependency-management")
1417
implementation("org.springframework.boot:spring-boot-starter")
1518
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
1619
implementation("org.springframework.boot:spring-boot-starter-data-redis")
1720
implementation("org.springframework.boot:spring-boot-starter-web")
1821

1922
testImplementation("org.springframework.boot:spring-boot-starter-test")
2023
testImplementation("org.testcontainers:testcontainers")
24+
25+
2126
}
2227

23-
compileKotlin {
28+
tasks.withType<KotlinCompile> {
2429
kotlinOptions {
30+
freeCompilerArgs = listOf("-Xjsr305=strict")
2531
jvmTarget = "1.8"
26-
freeCompilerArgs = ["-Xjsr305=strict"]
2732
}
2833
}

examples/spring-boot-kotlin-redis/src/main/kotlin/com/example/redis/ExampleController.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.example.redis
22

3-
import org.springframework.beans.factory.annotation.Autowired
43
import org.springframework.data.redis.core.RedisTemplate
54
import org.springframework.web.bind.annotation.GetMapping
65
import org.springframework.web.bind.annotation.PostMapping
76
import org.springframework.web.bind.annotation.RequestBody
87
import org.springframework.web.bind.annotation.RestController
98

109
@RestController
11-
class ExampleController {
10+
class ExampleController(
11+
private val redisTemplate: RedisTemplate<String, String>
12+
) {
1213

13-
private val key = "testcontainers"
14-
15-
@Autowired
16-
private lateinit var redisTemplate: RedisTemplate<String, String>
14+
companion object {
15+
const val key = "testcontainers"
16+
}
1717

1818
@PostMapping("/set-foo")
1919
fun setFoo(@RequestBody value: String) {

0 commit comments

Comments
 (0)