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
190
Dive Into Single Fetch
gothedistance
1
190
クラフトマンシップ(職人魂)を湾岸MIDNIGHTから学ぼう / Learn Craftsmanship from Wangan Midnight
gothedistance
0
260
プロ野球をデータモデリングしてみたら沼だった件 / Baseball ERD Modeling to be obsessed
gothedistance
2
770
フロントエンド開発スタイルの変遷と、私が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
LLMで構造化出力の成功率をグンと上げる方法
keisuketakiguchi
0
840
✨敗北解法コレクション✨〜Expertだった頃に足りなかった知識と技術〜
nanachi
1
720
九州の人に知ってもらいたいGISスポット / gis spot in kyushu 2025
sakaik
0
160
生成AI導入の効果を最大化する データ活用戦略
ham0215
0
160
Kiroでインフラ要件定義~テスト を実施してみた
nagisa53
3
360
AIに頼りすぎない新人育成術
cuebic9bic
3
310
AIのグローバルトレンド 2025 / ai global trend 2025
kyonmm
PRO
1
140
Rubyの国のPerlMonger
anatofuz
3
740
薬屋のひとりごとにみるトラブルシューティング
tomokusaba
0
340
形式手法特論:位相空間としての並行プログラミング #kernelvm / Kernel VM Study Tokyo 18th
ytaka23
3
1.4k
AI時代の大規模データ活用とセキュリティ戦略
ken5scal
0
130
Amazon Q と『音楽』-ゲーム音楽もAmazonQで作成してみた感想-
senseofunity129
0
140
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
49
14k
BBQ
matthewcrist
89
9.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
A designer walks into a library…
pauljervisheath
207
24k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Producing Creativity
orderedlist
PRO
347
40k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
For a Future-Friendly Web
brad_frost
179
9.9k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Building Applications with DynamoDB
mza
96
6.5k
A Modern Web Designer's Workflow
chriscoyier
695
190k
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である必 要が無いし…以下略