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
750
フロントエンド開発スタイルの変遷と、私が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
850
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 テクニカルサポートとエンドカスタマーの中間地点から見えるより良いサポートの活用方法
kazzpapa3
2
540
ひとり情シスなCTOがLLMと始めるオペレーション最適化 / CTO's LLM-Powered Ops
yamitzky
0
430
より良いプロダクトの開発を目指して - 情報を中心としたプロダクト開発 #phpcon #phpcon2025
bengo4com
1
3.1k
Amazon S3標準/ S3 Tables/S3 Express One Zoneを使ったログ分析
shigeruoda
4
480
Абьюзим random_bytes(). Фёдор Кулаков, разработчик Lamoda Tech
lamodatech
0
340
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
0
140
Snowflake Summit 2025 データエンジニアリング関連新機能紹介 / Snowflake Summit 2025 What's New about Data Engineering
tiltmax3
0
310
第9回情シス転職ミートアップ_テックタッチ株式会社
forester3003
0
230
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
1
160
Windows 11 で AWS Documentation MCP Server 接続実践/practical-aws-documentation-mcp-server-connection-on-windows-11
emiki
0
960
VISITS_AIIoTビジネス共創ラボ登壇資料.pdf
iotcomjpadmin
0
160
LinkX_GitHubを基点にした_AI時代のプロジェクトマネジメント.pdf
iotcomjpadmin
0
170
Featured
See All Featured
Designing for Performance
lara
609
69k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Music & Morning Musume
bryan
46
6.6k
Building Adaptive Systems
keathley
43
2.6k
RailsConf 2023
tenderlove
30
1.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
930
Testing 201, or: Great Expectations
jmmastey
42
7.5k
What's in a price? How to price your products and services
michaelherold
246
12k
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である必 要が無いし…以下略