Skip to content

Commit 59aa383

Browse files
committed
KTLN-587 added webmvc module
1 parent 6fba929 commit 59aa383

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

kotlin-dsl/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>kotlin-dsl</artifactId>
7+
<packaging>jar</packaging>
8+
9+
<name>kotlin-dsl</name>
10+
11+
<parent>
12+
<groupId>com.baeldung</groupId>
13+
<artifactId>parent-boot-3</artifactId>
14+
<version>1.0.0-SNAPSHOT</version>
15+
<relativePath>../parent-boot-3</relativePath>
16+
</parent>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<sourceDirectory>src/main/kotlin</sourceDirectory>
27+
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
28+
<plugins>
29+
<plugin>
30+
<artifactId>kotlin-maven-plugin</artifactId>
31+
<executions>
32+
<execution>
33+
<id>compile</id>
34+
<phase>compile</phase>
35+
<goals>
36+
<goal>compile</goal>
37+
</goals>
38+
</execution>
39+
<execution>
40+
<id>test-compile</id>
41+
<phase>test-compile</phase>
42+
<goals>
43+
<goal>test-compile</goal>
44+
</goals>
45+
</execution>
46+
</executions>
47+
<groupId>org.jetbrains.kotlin</groupId>
48+
<version>${kotlin.version}</version>
49+
<configuration>
50+
<args>
51+
<arg>-Xjsr305=strict</arg>
52+
</args>
53+
<jvmTarget>1.8</jvmTarget>
54+
<compilerPlugins>
55+
<plugin>spring</plugin>
56+
<plugin>jpa</plugin>
57+
</compilerPlugins>
58+
</configuration>
59+
<dependencies>
60+
<dependency>
61+
<groupId>org.jetbrains.kotlin</groupId>
62+
<artifactId>kotlin-maven-allopen</artifactId>
63+
<version>${kotlin.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.jetbrains.kotlin</groupId>
67+
<artifactId>kotlin-maven-noarg</artifactId>
68+
<version>${kotlin.version}</version>
69+
</dependency>
70+
</dependencies>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.functional_dsl.bean_declration
2+
3+
import java.math.BigDecimal
4+
import org.springframework.boot.autoconfigure.SpringBootApplication
5+
import org.springframework.boot.runApplication
6+
import org.springframework.context.support.BeanDefinitionDsl
7+
import org.springframework.context.support.beans
8+
9+
@SpringBootApplication
10+
open class Application
11+
12+
fun main(vararg args: String) {
13+
runApplication<Application>(*args) {
14+
addInitializers(
15+
beans {
16+
bean(
17+
name = "functionallyDeclaredBean",
18+
scope = BeanDefinitionDsl.Scope.SINGLETON,
19+
isLazyInit = false,
20+
isPrimary = false,
21+
function = {
22+
BigDecimal(1.0)
23+
}
24+
)
25+
}
26+
)
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.functional_dsl.regular_controller
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import org.springframework.boot.runApplication
5+
import org.springframework.web.bind.annotation.GetMapping
6+
import org.springframework.web.bind.annotation.PathVariable
7+
import org.springframework.web.bind.annotation.RequestHeader
8+
import org.springframework.web.bind.annotation.RequestParam
9+
import org.springframework.web.bind.annotation.RestController
10+
11+
@RestController
12+
class RegularController {
13+
14+
@GetMapping(path = ["/endpoint/{country}"])
15+
fun getPerson(
16+
@RequestParam name: String,
17+
@RequestHeader(name = "X-age") age: String,
18+
@PathVariable country: String
19+
) : Map<*, *> {
20+
return mapOf(
21+
"name" to name,
22+
"age" to age,
23+
"country" to country
24+
)
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.functional_dsl.router_function
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import org.springframework.boot.runApplication
5+
import org.springframework.context.annotation.Bean
6+
import org.springframework.web.servlet.function.RouterFunction
7+
import org.springframework.web.servlet.function.RouterFunctions
8+
import org.springframework.web.servlet.function.ServerRequest
9+
import org.springframework.web.servlet.function.ServerResponse
10+
11+
@SpringBootApplication
12+
open class Application {
13+
14+
@Bean
15+
open fun configure() : RouterFunction<ServerResponse> {
16+
return RouterFunctions.route()
17+
.GET("/endpoint/{country}") {
18+
ServerResponse.ok().body(
19+
mapOf(
20+
"name" to it.param("name"),
21+
"age" to it.headers().header("X-age")[0],
22+
"country" to it.pathVariable("country")
23+
)
24+
)
25+
}
26+
.build()
27+
}
28+
}
29+
30+
fun main(vararg args: String) {
31+
runApplication<Application>(*args)
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.functional_dsl.router_function_dsl
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import org.springframework.boot.runApplication
5+
import org.springframework.context.support.beans
6+
import org.springframework.web.servlet.function.ServerRequest
7+
import org.springframework.web.servlet.function.ServerResponse
8+
import org.springframework.web.servlet.function.router
9+
10+
@SpringBootApplication
11+
open class Application
12+
13+
fun main(vararg args: String) {
14+
runApplication<Application>(*args)
15+
{
16+
addInitializers(
17+
beans {
18+
bean {
19+
router {
20+
GET("/endpoint/{country}") { it : ServerRequest ->
21+
ServerResponse.ok().body(
22+
mapOf(
23+
"name" to it.param("name"),
24+
"age" to it.headers().header("X-age")[0],
25+
"country" to it.pathVariable("country")
26+
)
27+
)
28+
}
29+
}
30+
}
31+
}
32+
)
33+
}
34+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@
502502
<!-- <module>kotlin-js</module> --> <!-- not a Maven module -->
503503
<module>kotlin-json</module>
504504
<module>kotlin-json-2</module>
505+
<module>kotlin-dsl</module>
505506
<!-- <module>kotlin-ktor</module> --> <!-- not a Maven module -->
506507
<module>kotlin-lambda</module>
507508
<module>kotlin-libraries</module>

0 commit comments

Comments
 (0)