File tree Expand file tree Collapse file tree 9 files changed +106
-22
lines changed
kotlin/com/example/kotlin Expand file tree Collapse file tree 9 files changed +106
-22
lines changed Original file line number Diff line number Diff line change 1- buildscript {
2- ext {
3- springBootVersion = ' 2.1.3.RELEASE'
4- }
5- repositories {
6- mavenCentral()
7- }
8- dependencies {
9- classpath(" org.springframework.boot:spring-boot-gradle-plugin:${ springBootVersion} " )
10- }
1+ plugins {
2+ id ' org.springframework.boot' version ' 2.1.3.RELEASE'
3+ id ' org.jetbrains.kotlin.jvm' version ' 1.2.71'
4+ id ' org.jetbrains.kotlin.plugin.spring' version ' 1.2.71'
5+ id " org.jetbrains.kotlin.plugin.jpa" version " 1.2.71"
116}
127
13- apply plugin : ' java'
14- apply plugin : ' eclipse'
15- apply plugin : ' org.springframework.boot'
168apply plugin : ' io.spring.dependency-management'
179
1810group = ' com.example'
1911version = ' 0.0.1-SNAPSHOT'
20- sourceCompatibility = 1.8
12+ sourceCompatibility = ' 1.8'
2113
2214repositories {
2315 mavenCentral()
2416}
2517
2618dependencies {
27- compile(" org.springframework.boot:spring-boot-starter-web" )
28- testCompile(" org.springframework.boot:spring-boot-starter-test" )
29- }
19+ implementation ' org.springframework.boot:spring-boot-starter-web'
20+ implementation ' org.springframework.boot:spring-boot-starter-webflux'
21+ implementation ' com.fasterxml.jackson.module:jackson-module-kotlin'
22+ implementation ' org.jetbrains.kotlin:kotlin-reflect'
23+ implementation ' org.jetbrains.kotlin:kotlin-stdlib-jdk8'
24+
25+ testImplementation ' org.springframework.boot:spring-boot-starter-test'
26+ }
27+
28+ compileKotlin {
29+ kotlinOptions {
30+ freeCompilerArgs = [' -Xjsr305=strict' ]
31+ jvmTarget = ' 1.8'
32+ }
33+ }
34+
35+ compileTestKotlin {
36+ kotlinOptions {
37+ freeCompilerArgs = [' -Xjsr305=strict' ]
38+ jvmTarget = ' 1.8'
39+ }
40+ }
Original file line number Diff line number Diff line change 1- package com .tistory . heowc ;
1+ package com .example . java ;
22
33import org .springframework .boot .SpringApplication ;
44import org .springframework .boot .autoconfigure .SpringBootApplication ;
Original file line number Diff line number Diff line change 1- package com .tistory . heowc .config ;
1+ package com .example . java .config ;
22
33import org .springframework .context .annotation .Bean ;
44import org .springframework .context .annotation .Configuration ;
Original file line number Diff line number Diff line change 1- package com .tistory . heowc .domain ;
1+ package com .example . java .domain ;
22
33public class Message {
44
Original file line number Diff line number Diff line change 1- package com .tistory . heowc .web ;
1+ package com .example . java .web ;
22
3- import com .tistory . heowc .domain .Message ;
3+ import com .example . java .domain .Message ;
44import org .springframework .web .bind .annotation .*;
55
66@ RestController
Original file line number Diff line number Diff line change 1+ package com.example.kotlin
2+
3+ import org.springframework.boot.autoconfigure.SpringBootApplication
4+ import org.springframework.boot.runApplication
5+
6+ @SpringBootApplication
7+ class SpringBootCorsApplication
8+
9+ fun main (args : Array <String >) {
10+ runApplication<SpringBootCorsApplication >(* args)
11+ }
Original file line number Diff line number Diff line change 1+ package com.example.kotlin.config
2+
3+ import org.springframework.context.annotation.Bean
4+ import org.springframework.context.annotation.Configuration
5+ import org.springframework.http.HttpMethod
6+ import org.springframework.web.servlet.config.annotation.CorsRegistry
7+ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
8+
9+ @Configuration
10+ class WebConfig {
11+
12+ @Bean
13+ fun webMvcConfigurer (): WebMvcConfigurer {
14+ return object : WebMvcConfigurer {
15+ override fun addCorsMappings (registry : CorsRegistry ) {
16+ registry.addMapping(" /message/**" )
17+ .allowedOrigins(" *" )
18+ .allowedMethods(HttpMethod .POST .name)
19+ .allowCredentials(false )
20+ .maxAge(3600 )
21+ }
22+ }
23+ }
24+
25+ // => webflux 사용시 작성법
26+ //
27+ // @Bean
28+ // fun webFluxConfigurer(): WebFluxConfigurer {
29+ // return object : WebFluxConfigurer {
30+ // override fun addCorsMappings(registry: CorsRegistry) {
31+ // registry.addMapping("/message/**")
32+ // .allowedOrigins("*")
33+ // .allowedMethods(HttpMethod.POST.name)
34+ // .allowCredentials(false)
35+ // .maxAge(3600)
36+ // }
37+ // }
38+ // }
39+ }
Original file line number Diff line number Diff line change 1+ package com.example.kotlin.domain
2+
3+ data class Message (val sender : String , val content : String )
Original file line number Diff line number Diff line change 1+ package com.example.kotlin.web
2+
3+ import com.example.kotlin.domain.Message
4+ import org.springframework.web.bind.annotation.*
5+
6+ @RestController
7+ @RequestMapping(" message" )
8+ class MessageController {
9+
10+ // @CrossOrigin
11+ @GetMapping(" {value}" )
12+ operator fun get (@PathVariable value : String ): String {
13+ return value
14+ }
15+
16+ @PostMapping
17+ fun post (@RequestBody message : Message ): Message {
18+ return message
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments