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
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
170
Dive Into Single Fetch
gothedistance
1
180
クラフトマンシップ(職人魂)を湾岸MIDNIGHTから学ぼう / Learn Craftsmanship from Wangan Midnight
gothedistance
0
250
プロ野球をデータモデリングしてみたら沼だった件 / Baseball ERD Modeling to be obsessed
gothedistance
2
760
フロントエンド開発スタイルの変遷と、私がFlutterにハマったわけ
gothedistance
8
12k
ITプロジェクトのはじめ方 / How to work around software project
gothedistance
27
150k
私がITプランナーを志すようになった理由、そして、目指していること / bpstudy142_why_i_wanna_be_a_it_plannner
gothedistance
1
860
ITプランナーの必要性を小一時間問い詰めたい / Why We need IT-Planner.
gothedistance
0
13k
IT企画をちゃんとやりたい#01 ガイダンス資料 / IT Planning do well_01
gothedistance
0
6.5k
Other Decks in Technology
See All in Technology
AWS Organizations 新機能!マルチパーティ承認の紹介
yhana
1
280
AI専用のリンターを作る #yumemi_patch
bengo4com
5
4.3k
OPENLOGI Company Profile for engineer
hr01
1
34k
united airlines ™®️ USA Contact Numbers: Complete 2025 Support Guide
flyunitedhelp
1
340
ビズリーチにおけるリアーキテクティング実践事例 / JJUG CCC 2025 Spring
visional_engineering_and_design
1
120
タイミーのデータモデリング事例と今後のチャレンジ
ttccddtoki
6
2.4k
OSSのSNSツール「Misskey」をさわってみよう(右下ワイプで私のOSCの20年を振り返ります) / 20250705-osc2025-do
akkiesoft
0
170
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
10
130k
Flutter向けPDFビューア、pdfrxのpdfium WASM対応について
espresso3389
0
130
品質と速度の両立:生成AI時代の品質保証アプローチ
odasho
1
360
IPA&AWSダブル全冠が明かす、人生を変えた勉強法のすべて
iwamot
PRO
2
140
NewSQLや分散データベースを支えるRaftの仕組み - 仕組みを理解して知る得意不得意
hacomono
PRO
2
160
Featured
See All Featured
Balancing Empowerment & Direction
lara
1
430
Become a Pro
speakerdeck
PRO
29
5.4k
Into the Great Unknown - MozCon
thekraken
40
1.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Practical Orchestrator
shlominoach
189
11k
Six Lessons from altMBA
skipperchong
28
3.9k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
Optimizing for Happiness
mojombo
379
70k
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である必 要が無いし…以下略