diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml
index b8c341afde..db4ffa9abb 100644
--- a/spring-5-mvc/pom.xml
+++ b/spring-5-mvc/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.baeldung
@@ -15,7 +15,8 @@
org.springframework.boot
spring-boot-starter-parent
2.0.0.M1
-
+
+
@@ -35,12 +36,12 @@
org.springframework.boot
spring-boot-starter-web
-
+
org.apache.commons
- commons-lang3
+ commons-lang3
org.slf4j
@@ -48,7 +49,24 @@
org.slf4j
- jcl-over-slf4j
+ jcl-over-slf4j
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jre8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-reflect
+ ${kotlin.version}
+
+
+ com.fasterxml.jackson.module
+ jackson-module-kotlin
+ 2.8.7
@@ -74,12 +92,12 @@
test
-
+
junit
junit
test
-
+
com.jayway.restassured
rest-assured
@@ -90,18 +108,58 @@
-
+ ${project.basedir}/src/main/kotlin
+ ${project.basedir}/src/test/kotlin
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ spring
+
+ 1.8
+
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-allopen
+ ${kotlin.version}
+
+
+
org.apache.maven.plugins
- maven-surefire-plugin
+ maven-surefire-plugin
- true
- false
-
- **/*IntegrationTest.java
- **/*LiveTest.java
-
-
+ true
+ false
+
+ **/*IntegrationTest.java
+ **/*LiveTest.java
+
+
@@ -145,10 +203,11 @@
- 2.9.0
+ 2.9.0
UTF-8
UTF-8
- 1.8
+ 1.8
+ 1.1.2
diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt
new file mode 100644
index 0000000000..69be7dac7e
--- /dev/null
+++ b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt
@@ -0,0 +1,23 @@
+package com.baeldung.springbootkotlin
+
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RestController
+
+@RestController
+class HelloController(val helloService: HelloService) {
+
+ @GetMapping("/hello")
+ fun helloKotlin(): String {
+ return "hello world"
+ }
+
+ @GetMapping("/hello-service")
+ fun helloKotlinService(): String {
+ return helloService.getHello()
+ }
+
+ @GetMapping("/hello-dto")
+ fun helloDto(): HelloDto {
+ return HelloDto("Hello from the dto")
+ }
+}
\ No newline at end of file
diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt
new file mode 100644
index 0000000000..f61c101f0f
--- /dev/null
+++ b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt
@@ -0,0 +1,3 @@
+package com.baeldung.springbootkotlin
+
+data class HelloDto(val greeting: String)
diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt
new file mode 100644
index 0000000000..67791a0c2d
--- /dev/null
+++ b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt
@@ -0,0 +1,11 @@
+package com.baeldung.springbootkotlin
+
+import org.springframework.stereotype.Service
+
+@Service
+class HelloService {
+
+ fun getHello(): String {
+ return "hello service"
+ }
+}
\ No newline at end of file
diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt
new file mode 100644
index 0000000000..dbe5694b6d
--- /dev/null
+++ b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt
@@ -0,0 +1,11 @@
+package com.baeldung.springbootkotlin
+
+import org.springframework.boot.SpringApplication
+import org.springframework.boot.autoconfigure.SpringBootApplication
+
+@SpringBootApplication
+class KotlinDemoApplication
+
+fun main(args: Array) {
+ SpringApplication.run(KotlinDemoApplication::class.java, *args)
+}
diff --git a/spring-5-mvc/src/test/kotlin/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt b/spring-5-mvc/src/test/kotlin/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt
new file mode 100644
index 0000000000..fbe83926ef
--- /dev/null
+++ b/spring-5-mvc/src/test/kotlin/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt
@@ -0,0 +1,53 @@
+package springbootkotlin
+
+import com.baeldung.springbootkotlin.HelloDto
+import com.baeldung.springbootkotlin.KotlinDemoApplication
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNotNull
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.boot.test.web.client.TestRestTemplate
+import org.springframework.http.HttpStatus
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@SpringBootTest(classes = arrayOf(KotlinDemoApplication::class), webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+class KotlinDemoApplicationIntegrationTest {
+
+ @Autowired
+ val testRestTemplate: TestRestTemplate? = null
+
+ @Test
+ fun contextLoads() {
+ }
+
+ @Test
+ fun testHelloController() {
+ val result = testRestTemplate?.getForEntity("/hello", String::class.java)
+
+ assertNotNull(result)
+ assertEquals(result?.statusCode, HttpStatus.OK)
+ assertEquals(result?.body, "hello world")
+ }
+
+ @Test
+ fun testHelloService() {
+ val result = testRestTemplate?.getForEntity("/hello-service", String::class.java)
+
+ assertNotNull(result)
+ assertEquals(result?.statusCode, HttpStatus.OK)
+ assertEquals(result?.body, "hello service")
+ }
+
+ @Test
+ fun testHelloDto() {
+ val result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
+
+ assertNotNull(result)
+ assertEquals(result?.statusCode, HttpStatus.OK)
+ assertEquals(result?.body, HelloDto("Hello from the dto"))
+ }
+
+}