Spring Fu on GraalVM

Spring Fu on GraalVM

Kotlin Developers Meetup (https://kotlin.connpass.com/event/90679/) で発表したスライドです

14c9795d267f5b85abb98ca5e8780646?s=128

Taro Nagasawa

June 27, 2018
Tweet

Transcript

  1. Spring Fu on GraalVM 2018-06-27 Taro Nagasawa

  2. Taro - たろう • @ngsw_taro • Organizer of Japan Kotlin

    User Group
  3. Redesign Medical Care

  4. GraalVM • Platform developed by Oracle • Polyglot VM ◦

    JVM-based languages (Java, Scala, Kotlin! …) ◦ JavaScript, Python, Ruby, R ◦ LLVM-based languages (C, C++, ...) • AOT Compiler ◦ Java code is compiled to native code • Community Edition / Enterprise Edition
  5. $ docker run --rm findepi/graalvm java -version openjdk version "1.8.0_171"

    OpenJDK Runtime Environment (build 1.8.0_171-11) GraalVM 1.0.0-rc2 (build25.71-b01-internal-jvmci -0.43, mixed mode)
  6. Familiar Spring Boot application @SpringBootApplication class DemoApplication fun main(args: Array<String>)

    { runApplication<DemoApplication>(*args) } @Service class HelloService { fun hello(): String = "Hello, world!" } @RestController class HelloController(val helloService: HelloService) { @GetMapping("") fun hello(): String = helloService.hello() }
  7. $ ./gradlew bootRun $ curl http://localhost:8080 Hello, world! Spring app

    written in Kotlin runs on GraalVM
  8. $ ./gradlew assemble $ native-image -jar\ build/libs/demo-0.0.1-SNAPSHOT.jar Native

  9. $ ./gradlew assemble $ native-image -jar\ build/libs/demo-0.0.1-SNAPSHOT.jar Error: com.oracle.graal.pointsto.constraints.Un supportedFeatureException:

    Unsupported field jav a.net.URL.handlers is reachable Native
  10. Spring Fu • Micro-framework for Kotlin • Like Spring 5

    functional registration
  11. Hello, Spring Fu class HelloService { fun hello(): String =

    "Hello, world!" } class HelloController(val helloService: HelloService) { fun hello(request: ServerRequest): Mono<ServerResponse> { val hello = helloService.hello() return ServerResponse.ok().syncBody(hello) } }
  12. Hello, Spring Fu fun main(args: Array<String>) = application { bean<HelloService>()

    bean<HelloController>() webflux { server(netty(8080)) { routes { this.context = this@application.context val helloController = ref<HelloController>() GET("/", helloController::hello) } } } }.run(await = true)
  13. Hello, Spring Fu fun main(args: Array<String>) = application { bean<HelloService>()

    bean<HelloController>() webflux { server(netty(8080)) { routes { this.context = this@application.context val helloController = ref<HelloController>() GET("/", helloController::hello) } } } }.run(await = true)
  14. $ ./gradlew bootRun $ curl http://localhost:8080 Hello, world! Spring Fu

    app runs on GraalVM
  15. $ ./gradlew assemble $ native-image -jar build/libs/app.jar Native!

  16. $ ./gradlew assemble $ native-image -jar build/libs/app.jar Error: com.oracle.graal.pointsto.constraints.Un supportedFeatureException:

    Unsupported field jav a.net.URL.handlers is reachable Native!
  17. Spring Fu does not support GraalVM AOT compiler

  18. None
  19. One more thing...

  20. Kotlin Fest 2018 Tokyo Aug. 25th More information coming soon.

  21. Thank you! Enjoy Kotlin!