Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring Fu on GraalVM

Spring Fu on GraalVM

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

Taro Nagasawa

June 27, 2018
Tweet

More Decks by Taro Nagasawa

Other Decks in Programming

Transcript

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

    View full-size slide

  2. Taro - たろう
    ● @ngsw_taro
    ● Organizer of Japan Kotlin User Group

    View full-size slide

  3. Redesign Medical Care

    View full-size slide

  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

    View full-size slide

  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)

    View full-size slide

  6. Familiar Spring Boot application
    @SpringBootApplication class DemoApplication
    fun main(args: Array) {
    runApplication(*args)
    }
    @Service
    class HelloService {
    fun hello(): String = "Hello, world!"
    }
    @RestController
    class HelloController(val helloService: HelloService) {
    @GetMapping("")
    fun hello(): String = helloService.hello()
    }

    View full-size slide

  7. $ ./gradlew bootRun
    $ curl http://localhost:8080
    Hello, world!
    Spring app written in Kotlin runs on GraalVM

    View full-size slide

  8. $ ./gradlew assemble
    $ native-image -jar\
    build/libs/demo-0.0.1-SNAPSHOT.jar
    Native

    View full-size slide

  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

    View full-size slide

  10. Spring Fu
    ● Micro-framework for Kotlin
    ● Like Spring 5 functional registration

    View full-size slide

  11. Hello, Spring Fu
    class HelloService {
    fun hello(): String = "Hello, world!"
    }
    class HelloController(val helloService: HelloService) {
    fun hello(request: ServerRequest): Mono {
    val hello = helloService.hello()
    return ServerResponse.ok().syncBody(hello)
    }
    }

    View full-size slide

  12. Hello, Spring Fu
    fun main(args: Array) = application {
    bean()
    bean()
    webflux {
    server(netty(8080)) {
    routes {
    this.context = [email protected]
    val helloController = ref()
    GET("/", helloController::hello)
    }
    }
    }
    }.run(await = true)

    View full-size slide

  13. Hello, Spring Fu
    fun main(args: Array) = application {
    bean()
    bean()
    webflux {
    server(netty(8080)) {
    routes {
    this.context = [email protected]
    val helloController = ref()
    GET("/", helloController::hello)
    }
    }
    }
    }.run(await = true)

    View full-size slide

  14. $ ./gradlew bootRun
    $ curl http://localhost:8080
    Hello, world!
    Spring Fu app runs on GraalVM

    View full-size slide

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

    View full-size slide

  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!

    View full-size slide

  17. Spring Fu
    does not support
    GraalVM
    AOT compiler

    View full-size slide

  18. One more thing...

    View full-size slide

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

    View full-size slide

  20. Thank you!
    Enjoy Kotlin!

    View full-size slide