Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor spring-boot-kotlin-redis example to be more Kotlin idiomatic #7185

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading