Skip to content

Commit

Permalink
Refactor spring-boot-kotlin-redis example to be more Kotlin idiomatic (
Browse files Browse the repository at this point in the history
…#7185)

Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
  • Loading branch information
jitokim and eddumelendez committed Jun 20, 2023
1 parent 9220816 commit d106d3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.7.10"
id("org.jetbrains.kotlin.jvm") version "1.8.10"
id("org.jetbrains.kotlin.plugin.spring") version "1.8.20"
kotlin("jvm") version "1.8.10"
kotlin("plugin.spring") version "1.8.20"
}

apply plugin: 'io.spring.dependency-management'
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
}

dependencies {
apply(plugin = "io.spring.dependency-management")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.boot:spring-boot-starter-web")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.testcontainers:testcontainers")


}

compileKotlin {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
freeCompilerArgs = ["-Xjsr305=strict"]
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.example.redis

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@RestController
class ExampleController {
class ExampleController(
private val redisTemplate: RedisTemplate<String, String>
) {

private val key = "testcontainers"

@Autowired
private lateinit var redisTemplate: RedisTemplate<String, String>
companion object {
const val key = "testcontainers"
}

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

0 comments on commit d106d3f

Please sign in to comment.