Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SpringBootとKotlinでサクッと作るWebサービス
Search
YUMOTO Michitaka
December 05, 2017
Technology
0
1.1k
SpringBootとKotlinでサクッと作るWebサービス
DocurainのWeb-API部分の実装やバックエンドについての資料です。
https://quality-start.in/docurain
YUMOTO Michitaka
December 05, 2017
Tweet
Share
More Decks by YUMOTO Michitaka
See All by YUMOTO Michitaka
Short Introduction for Kysely
gothedistance
1
310
Dive Into Single Fetch
gothedistance
1
220
クラフトマンシップ(職人魂)を湾岸MIDNIGHTから学ぼう / Learn Craftsmanship from Wangan Midnight
gothedistance
0
290
プロ野球をデータモデリングしてみたら沼だった件 / Baseball ERD Modeling to be obsessed
gothedistance
2
820
フロントエンド開発スタイルの変遷と、私がFlutterにハマったわけ
gothedistance
8
13k
ITプロジェクトのはじめ方 / How to work around software project
gothedistance
27
150k
私がITプランナーを志すようになった理由、そして、目指していること / bpstudy142_why_i_wanna_be_a_it_plannner
gothedistance
1
910
ITプランナーの必要性を小一時間問い詰めたい / Why We need IT-Planner.
gothedistance
0
14k
IT企画をちゃんとやりたい#01 ガイダンス資料 / IT Planning do well_01
gothedistance
0
6.5k
Other Decks in Technology
See All in Technology
半年で、AIゼロ知識から AI中心開発組織の変革担当に至るまで
rfdnxbro
0
150
Building Serverless AI Memory with Mastra × AWS
vvatanabe
1
750
Agent Skillsがハーネスの垣根を超える日
gotalab555
6
4.7k
さくらのクラウド開発ふりかえり2025
kazeburo
2
1.2k
2025-12-27 Claude CodeでPRレビュー対応を効率化する@機械学習社会実装勉強会第54回
nakamasato
4
1.2k
Keynoteから見るAWSの頭の中
nrinetcom
PRO
1
110
TED_modeki_共創ラボ_20251203.pdf
iotcomjpadmin
0
170
SES向け、生成AI時代におけるエンジニアリングとセキュリティ
longbowxxx
0
120
Microsoft Agent Frameworkの可観測性
tomokusaba
1
120
LayerX QA Night#1
koyaman2
0
280
ECS_EKS以外の選択肢_ROSA入門_.pdf
masakiokuda
1
110
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
1.1k
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
98
My Coaching Mixtape
mlcsv
0
14
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
400
Faster Mobile Websites
deanohume
310
31k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
720
WENDY [Excerpt]
tessaabrams
9
35k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Accessibility Awareness
sabderemane
0
26
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
130
Transcript
Spring boot + Kotlinで Webサービスをサクッと作ってみた by makoto yuri
自己紹介 経験が長い→ C, C# 最近やってる→Java / Spring boot / JS
好き → Scala / Play Framework 由利 誠 (withpop) @anoparanominal (twitter) https://anopara.net (blog) フリーランス
伝えたいこと • ScalaやPlayと比較してJavaやSpringはど う感じたか • Spring bootを使った感想 • Spring boot
+ Kotlinの組み合わせはどうな のか
None
帳票作成サービス Docurain • Excelで作った帳票テンプレートにJSONでデー タを流し込んでPDF/Excel/画像を返却 • If/foreachなどの制御構造を使用可能 • Excelの機能(グラフ、スタイル、数式)が大体 動作する
• プレビュー版公開中なのでご興味がある方は是 非
簡単なデモ
Docurainの開発 Load Balancer Console / API Application Server Core Engine
Server Redis Maria DB Spring boot / Kotlin S3
Spring bootの良い点 • デプロイが超絶簡単 – executable jarへのシンボリックリンクをinit.d下に貼 るだけ • フルスタックなのでライブラリ選定で悩まない
• Spring Security便利 – Redisへのセッション吐き出し – 認可 – BCrypt • Tomcatで動く – Tomcatで動くことを要求されることが多い • あまり特殊なことをしなければ生産性がとても 高い
Spring bootのつらみ • annotationに頼りすぎ – 処理が散逸する 関心事が一つにまとまらない – 実行しないとエラーが分からない –
知らないと辛い(学習コストが高い) • Controllerの作り方がわかりにくい – クッキーをいじるには?Statusコードはどうすれ ばいいの?入出力のContent-Typeを動的に変更す るには? – 入力(Request)と出力(Response)の型がガッ チリ決まっててほしい
Spring bootのつらみの例 @Controller @ResponseBody class UserController { @GetMapping(“/users/{userId}”) fun getUser(@PathVariable
userId: String): Boolean { return userModel.getUserId(userId) ?: UserNotFoundException() } } @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) class UserNotFoundException() : Exception() @ControllerAdvice class ExceptionHandler { @ExceptionHandler(UserNotFoundException::Class) fun userNotFound(): ResponseEntity<String>{ return ResponseEntity(“user not found.”, HttpStatus.NOT_FOUND) } Userを返却するという関心事が 散逸してしまう。 せめてgetUser()の中で完結して ほしい
Kotlin + Springの良い点 • 「Kotlinだから出来ない」は無かった • 拡張メソッドが充実してて痒いところに 手が届く – joinString,
stripMargin, use • Null safetyの演算子はまあまあ便利 – 特定の問題を解決するためだけに演算子を定 義してしまうのは個人的にはあんまり綺麗と は思わない • Kotlinの学習コストは低め
Kotlin + Springのつらみ • String Interpolationが常時動作するのがうざい 例: @Value(“¥${foo.baa}”) • Beanを定義するときにdata
classの恩恵が薄い。 Lombokのほうが楽に感じた • パターンマッチもScala比で出来ることが少なく なってる • 落とし穴が多い気がする(Kotlinの言語仕様)
fun foo(): Boolean { return listOf(1, 2, 3).all { return
it == 1 } } 落とし穴の例 foo()の実行結果は? その他の愚痴→ http://anopara.net/2017/09/16/kotlinの気に入らないところ/
まとめ • Spring boot / Kotlinの組み合わせはプロダク トでも十分使える • なんだかんだでKotlinはBetter Javaと言うに
相応しいと思う。Kotlin使えるなら使ったほ うが良い • Javaからの乗り換えを容易にした分、アドバ ンテージも小さくなってる気が • Javaも進化しているので、今Kotlinに積極的 に乗り換える理由があるかというと…?そもそ も人は集められるのか…?
おわり Docurain使ってみてね!!
Scala / Play との比較 • シンプルでわかりやすい – 学習コストはSpring bootよりPlayのほうが低いと感 じる
• ライブラリの選定で悩むところが多い – JSONライブラリだけで5~6くらいある? • filterやAOP相当の処理は関数合成で行う – ソースコードを追っていける • より型安全 • Scalaはコミュニティが殺伐としてる(※個人的感想)
Kotlin - Null Safety val x = request.getHeader(“Authorization”) ?: throw
NoAuthInfoException(“auth header required.”) val y = bob?.department?.head?.name C#にもNull許容型に似たような演算子がある。 PHPにもある?(よく知らない) Null安全のためにしか使えない演算子よりも、モナドとモナド用の構文 があったほうが汎用性があるような…しかしそれを言うとKotlinである必 要が無いし…以下略