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

More Related Content

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

What's hot

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

Similar to Spring ❤️ Kotlin #jjug

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

More from Toshiaki Maki

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

Recently uploaded

PDF
Day 1 - Cloud Security Strategy and Planning ~ 2nd Sight Lab ~ Cloud Security...
PPTX
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
PDF
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
PDF
The year in review - MarvelClient in 2025
PDF
GPUS and How to Program Them by Manya Bansal
PPTX
wob-report.pptxwob-report.pptxwob-report.pptx
PDF
Session 1 - Solving Semi-Structured Documents with Document Understanding
PDF
Is It Possible to Have Wi-Fi Without an Internet Provider
PPTX
Ethics in AI - Artificial Intelligence Fundamentals.pptx
PPTX
Unit-4-ARTIFICIAL NEURAL NETWORKS.pptx ANN ppt Artificial neural network
PDF
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
DOCX
Introduction to the World of Computers (Hardware & Software)
PDF
Making Sense of Raster: From Bit Depth to Better Workflows
PDF
Safeguarding AI-Based Financial Infrastructure
PDF
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
PDF
Six Shifts For 2026 (And The Next Six Years)
PPTX
Chapter 3 Introduction to number system.pptx
PPTX
From Backup to Resilience: How MSPs Are Preparing for 2026
 
PPTX
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
PPTX
AI's Impact on Cybersecurity - Challenges and Opportunities
Day 1 - Cloud Security Strategy and Planning ~ 2nd Sight Lab ~ Cloud Security...
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
The year in review - MarvelClient in 2025
GPUS and How to Program Them by Manya Bansal
wob-report.pptxwob-report.pptxwob-report.pptx
Session 1 - Solving Semi-Structured Documents with Document Understanding
Is It Possible to Have Wi-Fi Without an Internet Provider
Ethics in AI - Artificial Intelligence Fundamentals.pptx
Unit-4-ARTIFICIAL NEURAL NETWORKS.pptx ANN ppt Artificial neural network
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
Introduction to the World of Computers (Hardware & Software)
Making Sense of Raster: From Bit Depth to Better Workflows
Safeguarding AI-Based Financial Infrastructure
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
Six Shifts For 2026 (And The Next Six Years)
Chapter 3 Introduction to number system.pptx
From Backup to Resilience: How MSPs Are Preparing for 2026
 
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
AI's Impact on Cybersecurity - Challenges and Opportunities

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