Movatterモバイル変換


[0]ホーム

URL:


Toshiaki Maki, profile picture
Uploaded byToshiaki Maki
PDF, PPTX3,780 views

Spring ❤️ Kotlin #jjug

The document discusses Kotlin support in Spring Framework 5. It covers how Kotlin can be used with Spring Boot and Spring's programming model through features like extension functions and reified type parameters. It provides code examples of using Kotlin idioms with Spring components like the application context, JdbcTemplate, and RestTemplate to make the code more concise and readable. It also briefly mentions new features in Spring Framework 5 like reactive support using Spring WebFlux and using router functions with Kotlin.

Embed presentation

Download as PDF, PPTX
‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.Spring ❤ KotlinToshiaki Maki (@making)tmaki@pivotal.ioJJUG Night Seminar 2017 Feb2017-02-20
© 2016 Pivotal Software, Inc. All rights reserved.Who am I ?• Toshiaki Maki (@making) https://ik.am• Sr. Solutions Architect @Pivotal• Spring ☘ / Cloud Foundry ☁ / Concourse ✈ / BOSH 🐚bit.ly/hajiboot2
© 2016 Pivotal Software, Inc. All rights reserved.Agenda•Spring Boot with Kotlin•Kotlin support in Spring 5
‹#›© 2016 Pivotal Software, Inc. All rights reserved.Spring Boot with Kotlin
© 2016 Pivotal Software, Inc. All rights reserved.Spring Initializr
© 2016 Pivotal Software, Inc. All rights reserved.Spring Initializr
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.package com.example

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
SpringApplication.run(DemoApplication::class.java, *args)
}

© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.package com.example

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController {
@GetMapping("/")
fun hello() = "Hello World!"
}

© 2016 Pivotal Software, Inc. All rights reserved.package com.example

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController {
@GetMapping("/")
fun hello() = "Hello World!"
}

© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}👇👇
© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}👇👇😩
© 2016 Pivotal Software, Inc. All rights reserved.Cglib and Spring// Javaclass AppConfig {
@Bean
RestTemplate restTemplate() {return new RestTemplate();}
}
© 2016 Pivotal Software, Inc. All rights reserved.Cglib and Spring// Javaclass AppConfig {
@Bean
RestTemplate restTemplate() {return new RestTemplate();}
}Singleton
© 2016 Pivotal Software, Inc. All rights reserved.Cglib and Spring (Pseudo Code)class AppConfig$$ extends AppConfig {@Override
RestTemplate restTemplate() {if (context.contains("restTemplate")) {return context.get("restTemplate");}return super.restTemplate();}
}
© 2016 Pivotal Software, Inc. All rights reserved.Cglib and Spring (Pseudo Code)class AppConfig$$ extends AppConfig {@Override
RestTemplate restTemplate() {if (context.contains("restTemplate")) {return context.get("restTemplate");}return super.restTemplate();}
}Methods in Kotlinare final by default !!open removes final
© 2016 Pivotal Software, Inc. All rights reserved.<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration></plugin>
© 2016 Pivotal Software, Inc. All rights reserved.open class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
© 2016 Pivotal Software, Inc. All rights reserved.open class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
© 2016 Pivotal Software, Inc. All rights reserved.class AppConfig {
@Bean
fun restTemplate() = RestTemplate()
}
© 2016 Pivotal Software, Inc. All rights reserved.class AppConfig {
@Bean
fun restTemplate() = RestTemplate()
}😍
© 2016 Pivotal Software, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
‹#›© 2016 Pivotal Software, Inc. All rights reserved.Kotlin support in Spring 5
© 2016 Pivotal Software, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support
© 2016 Pivotal Software, Inc. All rights reserved.Kotlin Support
© 2016 Pivotal Software, Inc. All rights reserved.Kotlin Support
© 2016 Pivotal Software, Inc. All rights reserved.Kotlin Support•Extension Functions•Reified type parameters
© 2016 Pivotal Software, Inc. All rights reserved.Kotlin Support•Extension Functions•Reified type parameters🤔
© 2016 Pivotal Software, Inc. All rights reserved.package com.example;public class Foo {public <T> T create(Class<T> clazz) {try {return clazz.newInstance();}catch (Exception e) {throw new IllegalStateException(e);}}}
© 2016 Pivotal Software, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);
© 2016 Pivotal Software, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
© 2016 Pivotal Software, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)👇
© 2016 Pivotal Software, Inc. All rights reserved.KClassBar::class // kotlin.reflect.KClassBar::class.java // java.lang.Class

© 2016 Pivotal Software, Inc. All rights reserved.Extension Functions•Extends a class with new functionalitywithout having to inherit from the class•https://kotlinlang.org/docs/reference/extensions.html#extension-functions
© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
© 2016 Pivotal Software, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class)
© 2016 Pivotal Software, Inc. All rights reserved.Extension Functions// Kotlinval foo = Foo()val bar = foo.create(Bar::class)
© 2016 Pivotal Software, Inc. All rights reserved.Extension Functionspackage com.exampleimport kotlin.reflect.KClassfun <T : Any> Foo.create(kclass: KClass<T>)= create(kclass.java)
FooExtensions.kt
© 2016 Pivotal Software, Inc. All rights reserved.Extension Functionspackage com.exampleimport kotlin.reflect.KClassfun <T : Any> Foo.create(kclass: KClass<T>)= create(kclass.java)
👇FooExtensions.kt
© 2016 Pivotal Software, Inc. All rights reserved.Extension Functions// Kotlinval foo = Foo()val bar = foo.create(Bar::class)😍
© 2016 Pivotal Software, Inc. All rights reserved.Reified type parameters•Access a type passed to us as a parameter•https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters
© 2016 Pivotal Software, Inc. All rights reserved.Reified type parametersinline fun <reified T : Any> Foo.create()= create(T::class.java)

© 2016 Pivotal Software, Inc. All rights reserved.Reified type parametersinline fun <reified T : Any> Foo.create()= create(T::class.java)
👇👇
© 2016 Pivotal Software, Inc. All rights reserved.val foo = Foo()val bar = foo.create(Bar::class)

© 2016 Pivotal Software, Inc. All rights reserved.val foo = Foo()val bar = foo.create(Bar::class)

© 2016 Pivotal Software, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar = foo.create<Bar>()
😍
© 2016 Pivotal Software, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar: Bar = foo.create()
😍
© 2016 Pivotal Software, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar: Bar = foo.create()
😍"idiomatic Kotlin code"
© 2016 Pivotal Software, Inc. All rights reserved."idiomatic Kotlin code" with Spring 5
© 2016 Pivotal Software, Inc. All rights reserved.Application Context// JavaApplicationContext context = ...;Bar bar = context.getBean(Bar.class);
© 2016 Pivotal Software, Inc. All rights reserved.Application Context (Extension)// Kotlinval context = ...val bar = context.getBean(Bar::class)

© 2016 Pivotal Software, Inc. All rights reserved.Application Context (Reified Type)// Kotlinval context = ...val bar = context.getBean<Bar>()

© 2016 Pivotal Software, Inc. All rights reserved.Application Context (Reified Type)// Kotlinval context = ...val bar: Bar = context.getBean()

© 2016 Pivotal Software, Inc. All rights reserved.JdbcTemplate// JavaLong count = jdbcTemplate.queryForObject("SELECT count(*) FROM foo", Long.class);
© 2016 Pivotal Software, Inc. All rights reserved.JdbcTemplate (Extension)// Kotlinval count = jdbcTemplate.queryForObject("SELECT count(*) FROM foo", Long::class)
© 2016 Pivotal Software, Inc. All rights reserved.JdbcTemplate (Reified Type)// Kotlinval count = jdbcTemplate.queryForObject<Long>("SELECT count(*) FROM foo")
© 2016 Pivotal Software, Inc. All rights reserved.JdbcTemplate (Reified Type)// Kotlinval count: Long = jdbcTemplate.queryForObject("SELECT count(*) FROM foo")
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate// JavaString foo = restTemplate.getForObject("http://abc.io",String.class);
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foo = restTemplate.getForObject<String>("http://abc.io");
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foo: String = restTemplate.getForObject("http://abc.io");
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.getForObject("http://abc.io",List<Foo>.class);
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.getForObject("http://abc.io",List<Foo>.class);Compile Error!
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.exchange("http://abc.io", HttpMethod.GET,null, newParameterizedTypeReference<List<Foo>>(){}).getBody();
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.exchange("http://abc.io", HttpMethod.GET,null, newParameterizedTypeReference<List<Foo>>(){}).getBody();💩
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate (Reified Type)
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foos: List<Foo> = restTemplate.getForObject("http://abc.io");
© 2016 Pivotal Software, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foos: List<Foo> = restTemplate.getForObject("http://abc.io");😍
© 2016 Pivotal Software, Inc. All rights reserved.Spring ❤ Kotlin
© 2016 Pivotal Software, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support
© 2016 Pivotal Software, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support👇👇
© 2016 Pivotal Software, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support👇👇🤔
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.WebMVC + @Controller in Java@RestControllerpublic class UserController {private final UserRepository repo;UserController(UserRepository repo) {/.../}@GetMappingList<User> users() {return repo.findAll();}}
© 2016 Pivotal Software, Inc. All rights reserved.WebFlux + @Controller in Java@RestControllerpublic class UserController {private final ReactiveUserRepository repo;UserController(ReactiveUserRepository repo) {/.../}@GetMappingFlux<User> users() {return repo.findAll();}}
© 2016 Pivotal Software, Inc. All rights reserved.WebFlux + @Controller in Java@RestControllerpublic class UserController {private final ReactiveUserRepository repo;UserController(ReactiveUserRepository repo) {/.../}@GetMappingFlux<User> users() {return repo.findAll();}}Non-Blocking!!
© 2016 Pivotal Software, Inc. All rights reserved.WebFlux + RouterFunction in Java
© 2016 Pivotal Software, Inc. All rights reserved.WebFlux + RouterFunction in JavaRouterFunction<?> routes =route(GET("/users"), req -> ok().body(repo.findAll(), User.class));
© 2016 Pivotal Software, Inc. All rights reserved.WebFlux + RouterFunction in Kotlin{accept(APPLICATION_JSON).apply {GET("/users",{ok().body(fromPublisher(repo.findAll())})}}
© 2016 Pivotal Software, Inc. All rights reserved.Check source code!!• https://github.com/mix-it/mixit• https://github.com/making/demo-router-functions
© 2016 Pivotal Software, Inc. All rights reserved.Other Kotlin Support•Functional Bean Registration with Kotlin•WebFlux functional API, the Kotlin way•Leveraging Kotlin nullable information•Kotlin Script based templates•...•https://speakerdeck.com/sdeleuze/functional-web-applications-with-kotlin-and-spring-5?
© 2016 Pivotal Software, Inc. All rights reserved.Release datehttps://jira.spring.io/browse/SPR
© 2016 Pivotal Software, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
© 2016 Pivotal Software, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
© 2016 Pivotal Software, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
© 2016 Pivotal Software, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
© 2016 Pivotal Software, Inc. All rights reserved.Resources• https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0• https://speakerdeck.com/sdeleuze• https://blog.ik.am/entries/407
© 2016 Pivotal Software, Inc. All rights reserved.CfP for JJUG CCC 2017 Spring•Submit Call for Paper!!! 🙇•http://www.java-users.jp/?p=2830

Recommended

PDF
Managing your Docker image continuously with Concourse CI
PDF
From Zero to Hero with REST and OAuth2 #jjug
PDF
Team Support in Concourse CI 2.0 #concourse_tokyo
PDF
Concourse x Spinnaker #concourse_tokyo
PDF
Spring Cloud Servicesの紹介 #pcf_tokyo
PDF
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
PDF
Cloud Foundy Java Client V 2.0 #cf_tokyo
PDF
Spring Cloud Function & Project riff #jsug
PDF
Short Lived Tasks in Cloud Foundry #cfdtokyo
PDF
Why PCF is the best platform for Spring Boot
PDF
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
PDF
Introduction to Concourse CI #渋谷Java
PDF
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
PDF
Microservices with Spring and Cloud Foundry
PDF
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
PDF
Introduction to Spring WebFlux #jsug #sf_a1
PDF
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
PPTX
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
PDF
今すぐ始めるCloud Foundry #hackt #hackt_k
PDF
クラウド時代の Spring Framework (aka Spring Framework in Cloud Era)
PDF
Spring5 New Features - Nov, 2017
PDF
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
PDF
Spring Cloud Stream with Kafka
PDF
SpringOne Platform recap 정윤진
PDF
Introduction to Cloud Foundry #JJUG
PPTX
Spring Cloud Netflixを使おう #jsug
PDF
Spring Boot Actuator 2.0 & Micrometer
PPTX
Building Web Apps in Ratpack
PPTX
K is for Kotlin
PDF
Intro to Kotlin

More Related Content

PDF
Managing your Docker image continuously with Concourse CI
PDF
From Zero to Hero with REST and OAuth2 #jjug
PDF
Team Support in Concourse CI 2.0 #concourse_tokyo
PDF
Concourse x Spinnaker #concourse_tokyo
PDF
Spring Cloud Servicesの紹介 #pcf_tokyo
PDF
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
PDF
Cloud Foundy Java Client V 2.0 #cf_tokyo
PDF
Spring Cloud Function & Project riff #jsug
Managing your Docker image continuously with Concourse CI
From Zero to Hero with REST and OAuth2 #jjug
Team Support in Concourse CI 2.0 #concourse_tokyo
Concourse x Spinnaker #concourse_tokyo
Spring Cloud Servicesの紹介 #pcf_tokyo
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
Cloud Foundy Java Client V 2.0 #cf_tokyo
Spring Cloud Function & Project riff #jsug

What's hot

PDF
Short Lived Tasks in Cloud Foundry #cfdtokyo
PDF
Why PCF is the best platform for Spring Boot
PDF
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
PDF
Introduction to Concourse CI #渋谷Java
PDF
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
PDF
Microservices with Spring and Cloud Foundry
PDF
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
PDF
Introduction to Spring WebFlux #jsug #sf_a1
PDF
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
PPTX
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
PDF
今すぐ始めるCloud Foundry #hackt #hackt_k
PDF
クラウド時代の Spring Framework (aka Spring Framework in Cloud Era)
PDF
Spring5 New Features - Nov, 2017
PDF
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
PDF
Spring Cloud Stream with Kafka
PDF
SpringOne Platform recap 정윤진
PDF
Introduction to Cloud Foundry #JJUG
PPTX
Spring Cloud Netflixを使おう #jsug
PDF
Spring Boot Actuator 2.0 & Micrometer
PPTX
Building Web Apps in Ratpack
Short Lived Tasks in Cloud Foundry #cfdtokyo
Why PCF is the best platform for Spring Boot
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
Introduction to Concourse CI #渋谷Java
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
Microservices with Spring and Cloud Foundry
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
Introduction to Spring WebFlux #jsug #sf_a1
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
今すぐ始めるCloud Foundry #hackt #hackt_k
クラウド時代の Spring Framework (aka Spring Framework in Cloud Era)
Spring5 New Features - Nov, 2017
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Spring Cloud Stream with Kafka
SpringOne Platform recap 정윤진
Introduction to Cloud Foundry #JJUG
Spring Cloud Netflixを使おう #jsug
Spring Boot Actuator 2.0 & Micrometer
Building Web Apps in Ratpack

Similar to Spring ❤️ Kotlin #jjug

PPTX
K is for Kotlin
PDF
Intro to Kotlin
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
PDF
Why Spring <3 Kotlin
PDF
Kotlin, smarter development for the jvm
PPTX
KotlinForJavaDevelopers-UJUG.pptx
PDF
Kotlin: A pragmatic language by JetBrains
PDF
Building microservices with Kotlin
PDF
Kotlin talk
PDF
Kotlin for Android Developers
PDF
Introduction to kotlin
PPTX
Nice to meet Kotlin
PPTX
Kotlin : Happy Development
PDF
Exploring Koltin on Android
PPTX
Introduction to kotlin + spring boot demo
PDF
Be More Productive with Kotlin
PPTX
從零開始學 Android
PPTX
Building Mobile Apps with Android
PPTX
Kotlin
PPTX
Introduction to kotlin
K is for Kotlin
Intro to Kotlin
Develop your next app with kotlin @ AndroidMakersFr 2017
Why Spring <3 Kotlin
Kotlin, smarter development for the jvm
KotlinForJavaDevelopers-UJUG.pptx
Kotlin: A pragmatic language by JetBrains
Building microservices with Kotlin
Kotlin talk
Kotlin for Android Developers
Introduction to kotlin
Nice to meet Kotlin
Kotlin : Happy Development
Exploring Koltin on Android
Introduction to kotlin + spring boot demo
Be More Productive with Kotlin
從零開始學 Android
Building Mobile Apps with Android
Kotlin
Introduction to kotlin

More from Toshiaki Maki

PDF
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
PDF
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
PDF
Open Service Broker APIとKubernetes Service Catalog #k8sjp
PDF
BOSH / CF Deployment in modern ways #cf_tokyo
PDF
Zipkin Components #zipkin_jp
PDF
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
PDF
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
PDF
Implement Service Broker with Spring Boot #cf_tokyo
PDF
Concourse CI Meetup Demo
PDF
Install Concourse CI with BOSH
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Open Service Broker APIとKubernetes Service Catalog #k8sjp
BOSH / CF Deployment in modern ways #cf_tokyo
Zipkin Components #zipkin_jp
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Implement Service Broker with Spring Boot #cf_tokyo
Concourse CI Meetup Demo
Install Concourse CI with BOSH

Recently uploaded

PPTX
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
PDF
Making Sense of Raster: From Bit Depth to Better Workflows
PPTX
Conversational Agents – Building Intelligent Assistants [Virtual Hands-on Wor...
PPTX
Coded Agents – with UiPath SDK + LangGraph [Virtual Hands-on Workshop]
PDF
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
PDF
The year in review - MarvelClient in 2025
PPTX
Data Privacy and Protection: Safeguarding Information in a Connected World
DOCX
Introduction to the World of Computers (Hardware & Software)
PDF
Security Forum Sessions from Houston 2025 Event
PPTX
wob-report.pptxwob-report.pptxwob-report.pptx
PDF
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
PDF
Unser Jahresrückblick – MarvelClient in 2025
PDF
API-First Architecture in Financial Systems
PDF
Our Digital Tribe_ Cultivating Connection and Growth in Our Slack Community 🌿...
PDF
Six Shifts For 2026 (And The Next Six Years)
PDF
Digit Expo 2025 - EICC Edinburgh 27th November
PPTX
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
PPTX
From Backup to Resilience: How MSPs Are Preparing for 2026
 
PDF
Dev Dives: AI that builds with you - UiPath Autopilot for effortless RPA & AP...
PDF
The major tech developments for 2026 by Pluralsight, a research and training ...
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
Making Sense of Raster: From Bit Depth to Better Workflows
Conversational Agents – Building Intelligent Assistants [Virtual Hands-on Wor...
Coded Agents – with UiPath SDK + LangGraph [Virtual Hands-on Workshop]
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
The year in review - MarvelClient in 2025
Data Privacy and Protection: Safeguarding Information in a Connected World
Introduction to the World of Computers (Hardware & Software)
Security Forum Sessions from Houston 2025 Event
wob-report.pptxwob-report.pptxwob-report.pptx
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
Unser Jahresrückblick – MarvelClient in 2025
API-First Architecture in Financial Systems
Our Digital Tribe_ Cultivating Connection and Growth in Our Slack Community 🌿...
Six Shifts For 2026 (And The Next Six Years)
Digit Expo 2025 - EICC Edinburgh 27th November
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
From Backup to Resilience: How MSPs Are Preparing for 2026
 
Dev Dives: AI that builds with you - UiPath Autopilot for effortless RPA & AP...
The major tech developments for 2026 by Pluralsight, a research and training ...

Spring ❤️ Kotlin #jjug

  • 1.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.Spring ❤ KotlinToshiaki Maki (@making)tmaki@pivotal.ioJJUG Night Seminar 2017 Feb2017-02-20
  • 2.
    © 2016 PivotalSoftware, Inc. All rights reserved.Who am I ?• Toshiaki Maki (@making) https://ik.am• Sr. Solutions Architect @Pivotal• Spring ☘ / Cloud Foundry ☁ / Concourse ✈ / BOSH 🐚bit.ly/hajiboot2
  • 3.
    © 2016 PivotalSoftware, Inc. All rights reserved.Agenda•Spring Boot with Kotlin•Kotlin support in Spring 5
  • 4.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved.Spring Boot with Kotlin
  • 5.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Initializr
  • 6.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Initializr
  • 7.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 8.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 9.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 10.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 11.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 12.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 13.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 14.
    © 2016 PivotalSoftware, Inc. All rights reserved.package com.example

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
SpringApplication.run(DemoApplication::class.java, *args)
}

  • 15.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 16.
    © 2016 PivotalSoftware, Inc. All rights reserved.package com.example

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController {
@GetMapping("/")
fun hello() = "Hello World!"
}

  • 17.
    © 2016 PivotalSoftware, Inc. All rights reserved.package com.example

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController {
@GetMapping("/")
fun hello() = "Hello World!"
}

  • 18.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
  • 19.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}👇👇
  • 20.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinopen class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}👇👇😩
  • 21.
    © 2016 PivotalSoftware, Inc. All rights reserved.Cglib and Spring// Javaclass AppConfig {
@Bean
RestTemplate restTemplate() {return new RestTemplate();}
}
  • 22.
    © 2016 PivotalSoftware, Inc. All rights reserved.Cglib and Spring// Javaclass AppConfig {
@Bean
RestTemplate restTemplate() {return new RestTemplate();}
}Singleton
  • 23.
    © 2016 PivotalSoftware, Inc. All rights reserved.Cglib and Spring (Pseudo Code)class AppConfig$$ extends AppConfig {@Override
RestTemplate restTemplate() {if (context.contains("restTemplate")) {return context.get("restTemplate");}return super.restTemplate();}
}
  • 24.
    © 2016 PivotalSoftware, Inc. All rights reserved.Cglib and Spring (Pseudo Code)class AppConfig$$ extends AppConfig {@Override
RestTemplate restTemplate() {if (context.contains("restTemplate")) {return context.get("restTemplate");}return super.restTemplate();}
}Methods in Kotlinare final by default !!open removes final
  • 25.
    © 2016 PivotalSoftware, Inc. All rights reserved.<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration></plugin>
  • 26.
    © 2016 PivotalSoftware, Inc. All rights reserved.open class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
  • 27.
    © 2016 PivotalSoftware, Inc. All rights reserved.open class AppConfig {
@Bean
open fun restTemplate() = RestTemplate()
}
  • 28.
    © 2016 PivotalSoftware, Inc. All rights reserved.class AppConfig {
@Bean
fun restTemplate() = RestTemplate()
}
  • 29.
    © 2016 PivotalSoftware, Inc. All rights reserved.class AppConfig {
@Bean
fun restTemplate() = RestTemplate()
}😍
  • 30.
    © 2016 PivotalSoftware, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
  • 31.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved.Kotlin support in Spring 5
  • 32.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support
  • 33.
    © 2016 PivotalSoftware, Inc. All rights reserved.Kotlin Support
  • 34.
    © 2016 PivotalSoftware, Inc. All rights reserved.Kotlin Support
  • 35.
    © 2016 PivotalSoftware, Inc. All rights reserved.Kotlin Support•Extension Functions•Reified type parameters
  • 36.
    © 2016 PivotalSoftware, Inc. All rights reserved.Kotlin Support•Extension Functions•Reified type parameters🤔
  • 37.
    © 2016 PivotalSoftware, Inc. All rights reserved.package com.example;public class Foo {public <T> T create(Class<T> clazz) {try {return clazz.newInstance();}catch (Exception e) {throw new IllegalStateException(e);}}}
  • 38.
    © 2016 PivotalSoftware, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);
  • 39.
    © 2016 PivotalSoftware, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
  • 40.
    © 2016 PivotalSoftware, Inc. All rights reserved.// JavaFoo foo = new Foo();Bar bar = foo.create(Bar.class);// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)👇
  • 41.
    © 2016 PivotalSoftware, Inc. All rights reserved.KClassBar::class // kotlin.reflect.KClassBar::class.java // java.lang.Class

  • 42.
    © 2016 PivotalSoftware, Inc. All rights reserved.Extension Functions•Extends a class with new functionalitywithout having to inherit from the class•https://kotlinlang.org/docs/reference/extensions.html#extension-functions
  • 43.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
  • 44.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class.java)
  • 45.
    © 2016 PivotalSoftware, Inc. All rights reserved.// Kotlinval foo = Foo()val bar = foo.create(Bar::class)
  • 46.
    © 2016 PivotalSoftware, Inc. All rights reserved.Extension Functions// Kotlinval foo = Foo()val bar = foo.create(Bar::class)
  • 47.
    © 2016 PivotalSoftware, Inc. All rights reserved.Extension Functionspackage com.exampleimport kotlin.reflect.KClassfun <T : Any> Foo.create(kclass: KClass<T>)= create(kclass.java)
FooExtensions.kt
  • 48.
    © 2016 PivotalSoftware, Inc. All rights reserved.Extension Functionspackage com.exampleimport kotlin.reflect.KClassfun <T : Any> Foo.create(kclass: KClass<T>)= create(kclass.java)
👇FooExtensions.kt
  • 49.
    © 2016 PivotalSoftware, Inc. All rights reserved.Extension Functions// Kotlinval foo = Foo()val bar = foo.create(Bar::class)😍
  • 50.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parameters•Access a type passed to us as a parameter•https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters
  • 51.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parametersinline fun <reified T : Any> Foo.create()= create(T::class.java)

  • 52.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parametersinline fun <reified T : Any> Foo.create()= create(T::class.java)
👇👇
  • 53.
    © 2016 PivotalSoftware, Inc. All rights reserved.val foo = Foo()val bar = foo.create(Bar::class)

  • 54.
    © 2016 PivotalSoftware, Inc. All rights reserved.val foo = Foo()val bar = foo.create(Bar::class)

  • 55.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar = foo.create<Bar>()
😍
  • 56.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar: Bar = foo.create()
😍
  • 57.
    © 2016 PivotalSoftware, Inc. All rights reserved.Reified type parametersval foo = Foo()val bar: Bar = foo.create()
😍"idiomatic Kotlin code"
  • 58.
    © 2016 PivotalSoftware, Inc. All rights reserved."idiomatic Kotlin code" with Spring 5
  • 59.
    © 2016 PivotalSoftware, Inc. All rights reserved.Application Context// JavaApplicationContext context = ...;Bar bar = context.getBean(Bar.class);
  • 60.
    © 2016 PivotalSoftware, Inc. All rights reserved.Application Context (Extension)// Kotlinval context = ...val bar = context.getBean(Bar::class)

  • 61.
    © 2016 PivotalSoftware, Inc. All rights reserved.Application Context (Reified Type)// Kotlinval context = ...val bar = context.getBean<Bar>()

  • 62.
    © 2016 PivotalSoftware, Inc. All rights reserved.Application Context (Reified Type)// Kotlinval context = ...val bar: Bar = context.getBean()

  • 63.
    © 2016 PivotalSoftware, Inc. All rights reserved.JdbcTemplate// JavaLong count = jdbcTemplate.queryForObject("SELECT count(*) FROM foo", Long.class);
  • 64.
    © 2016 PivotalSoftware, Inc. All rights reserved.JdbcTemplate (Extension)// Kotlinval count = jdbcTemplate.queryForObject("SELECT count(*) FROM foo", Long::class)
  • 65.
    © 2016 PivotalSoftware, Inc. All rights reserved.JdbcTemplate (Reified Type)// Kotlinval count = jdbcTemplate.queryForObject<Long>("SELECT count(*) FROM foo")
  • 66.
    © 2016 PivotalSoftware, Inc. All rights reserved.JdbcTemplate (Reified Type)// Kotlinval count: Long = jdbcTemplate.queryForObject("SELECT count(*) FROM foo")
  • 67.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate// JavaString foo = restTemplate.getForObject("http://abc.io",String.class);
  • 68.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foo = restTemplate.getForObject<String>("http://abc.io");
  • 69.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foo: String = restTemplate.getForObject("http://abc.io");
  • 70.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.getForObject("http://abc.io",List<Foo>.class);
  • 71.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.getForObject("http://abc.io",List<Foo>.class);Compile Error!
  • 72.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.exchange("http://abc.io", HttpMethod.GET,null, newParameterizedTypeReference<List<Foo>>(){}).getBody();
  • 73.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate// JavaList<Foo> foos = restTemplate.exchange("http://abc.io", HttpMethod.GET,null, newParameterizedTypeReference<List<Foo>>(){}).getBody();💩
  • 74.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate (Reified Type)
  • 75.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foos: List<Foo> = restTemplate.getForObject("http://abc.io");
  • 76.
    © 2016 PivotalSoftware, Inc. All rights reserved.RestTemplate (Reified Type)// Kotlinval foos: List<Foo> = restTemplate.getForObject("http://abc.io");😍
  • 77.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring ❤ Kotlin
  • 78.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support
  • 79.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support👇👇
  • 80.
    © 2016 PivotalSoftware, Inc. All rights reserved.Spring Framework 5•Java 8 baseline, Java 9 compatibility•Reactive Support & Spring WebFlux•Router Functions•Performance improvements•HTTP/2 support•Kotlin support👇👇🤔
  • 81.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 82.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebMVC + @Controller in Java@RestControllerpublic class UserController {private final UserRepository repo;UserController(UserRepository repo) {/.../}@GetMappingList<User> users() {return repo.findAll();}}
  • 83.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebFlux + @Controller in Java@RestControllerpublic class UserController {private final ReactiveUserRepository repo;UserController(ReactiveUserRepository repo) {/.../}@GetMappingFlux<User> users() {return repo.findAll();}}
  • 84.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebFlux + @Controller in Java@RestControllerpublic class UserController {private final ReactiveUserRepository repo;UserController(ReactiveUserRepository repo) {/.../}@GetMappingFlux<User> users() {return repo.findAll();}}Non-Blocking!!
  • 85.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebFlux + RouterFunction in Java
  • 86.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebFlux + RouterFunction in JavaRouterFunction<?> routes =route(GET("/users"), req -> ok().body(repo.findAll(), User.class));
  • 87.
    © 2016 PivotalSoftware, Inc. All rights reserved.WebFlux + RouterFunction in Kotlin{accept(APPLICATION_JSON).apply {GET("/users",{ok().body(fromPublisher(repo.findAll())})}}
  • 88.
    © 2016 PivotalSoftware, Inc. All rights reserved.Check source code!!• https://github.com/mix-it/mixit• https://github.com/making/demo-router-functions
  • 89.
    © 2016 PivotalSoftware, Inc. All rights reserved.Other Kotlin Support•Functional Bean Registration with Kotlin•WebFlux functional API, the Kotlin way•Leveraging Kotlin nullable information•Kotlin Script based templates•...•https://speakerdeck.com/sdeleuze/functional-web-applications-with-kotlin-and-spring-5?
  • 90.
    © 2016 PivotalSoftware, Inc. All rights reserved.Release datehttps://jira.spring.io/browse/SPR
  • 91.
    © 2016 PivotalSoftware, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
  • 92.
    © 2016 PivotalSoftware, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
  • 93.
    © 2016 PivotalSoftware, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
  • 94.
    © 2016 PivotalSoftware, Inc. All rights reserved.http://start.spring.io/#!language=kotlin
  • 95.
    © 2016 PivotalSoftware, Inc. All rights reserved.Resources• https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0• https://speakerdeck.com/sdeleuze• https://blog.ik.am/entries/407
  • 96.
    © 2016 PivotalSoftware, Inc. All rights reserved.CfP for JJUG CCC 2017 Spring•Submit Call for Paper!!! 🙇•http://www.java-users.jp/?p=2830

[8]ページ先頭

©2009-2025 Movatter.jp