From d768b378502650a036e35f44138650b1006bb435 Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Fri, 6 Sep 2024 09:21:44 +0200 Subject: [PATCH] Add Spring boot with Rest controller --- build.gradle.kts | 5 +++++ src/main/kotlin/Main.kt | 5 ----- src/main/kotlin/org/example/Application.kt | 11 +++++++++++ src/main/kotlin/org/example/HelloController.kt | 13 +++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) delete mode 100644 src/main/kotlin/Main.kt create mode 100644 src/main/kotlin/org/example/Application.kt create mode 100644 src/main/kotlin/org/example/HelloController.kt diff --git a/build.gradle.kts b/build.gradle.kts index c77ecf8..947bfd7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,8 @@ plugins { kotlin("jvm") version "2.0.0" + kotlin("plugin.spring") version "1.9.22" + id("org.springframework.boot") version "3.1.0" + id("io.spring.dependency-management") version "1.1.0" } group = "org.example" @@ -10,6 +13,8 @@ repositories { } dependencies { + implementation("org.springframework.boot:spring-boot-starter-web") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation(kotlin("test")) } diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt deleted file mode 100644 index 732adf1..0000000 --- a/src/main/kotlin/Main.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.example - -fun main() { - println("Hello World!") -} \ No newline at end of file diff --git a/src/main/kotlin/org/example/Application.kt b/src/main/kotlin/org/example/Application.kt new file mode 100644 index 0000000..8051ff6 --- /dev/null +++ b/src/main/kotlin/org/example/Application.kt @@ -0,0 +1,11 @@ +package org.example + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class Application + +fun main(args: Array) { + runApplication(*args) +} \ No newline at end of file diff --git a/src/main/kotlin/org/example/HelloController.kt b/src/main/kotlin/org/example/HelloController.kt new file mode 100644 index 0000000..6150380 --- /dev/null +++ b/src/main/kotlin/org/example/HelloController.kt @@ -0,0 +1,13 @@ +package org.example + +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class HelloController { + + @GetMapping("/hello") + fun sayHello(): String { + return "Hello, World!" + } +} \ No newline at end of file