Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SpringBoot 3.0 のNative Imageを試してみた
Search
Kazuhiro Seo
January 29, 2023
Programming
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SpringBoot 3.0 のNative Imageを試してみた
Kazuhiro Seo
January 29, 2023
More Decks by Kazuhiro Seo
See All by Kazuhiro Seo
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
530
GitHub ActionsとAWSをOIDC認証で連携する
kazuhiro1982
1
230
Gradleとちょっと仲良くなろう
kazuhiro1982
0
130
JavaとWebAssembly
kazuhiro1982
0
160
セッションデータの管理にSpring Sessionを利用する
kazuhiro1982
0
3.6k
AWSのLake Formation Governed Tablesを触ってみた
kazuhiro1982
0
460
VS CodeとRemote Containerで開発環境もコード管理しよう
kazuhiro1982
1
770
SpringBootをコンテナで動かしてみる
kazuhiro1982
0
440
Serverless FrameworkでWebサイトの更新を検知して通知する
kazuhiro1982
0
540
Other Decks in Programming
See All in Programming
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
190
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
150
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
260
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
RSSとCodexを使ってX投稿自動化してみた
ochtum
0
110
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
ソフトウェアラスタライザ
fadis
1
800
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
130
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
1.7k
Webの地図
yosuke_furukawa
PRO
5
3.8k
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
1k
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Cult of Friendly URLs
andyhume
79
7k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
930
The SEO identity crisis: Don't let AI make you average
varn
0
550
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
820
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
GraphQLとの向き合い方2022年版
quramy
50
15k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
780
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
230
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
420
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Transcript
SpringBoot 3.0 の Native Image を試してみた
自己紹介 妹尾 一弘 サーバーサイドエンジニア 最近Web 開発から遠のいている LT 駆動学習 Java Do
スタッフ
Spring Boot 3.0 リリース 🎉
Native Image のサポートがGA
Native Image 単独で実行可能となるようにビルドされたイメージ 起動時間が高速 メモリ使用量が削減できる コンテナイメージを縮小できる 完全に互換ではない
やってみた
サンプルコード 簡単なCRUD を行うREST API DynamoDB にアクセス
Bean @Data public class Item { private String id; private
String name; private String code; }
Controller @RestController @RequestMapping("/items") public class ItemController { @Autowired private ItemService
service; @GetMapping("/") public Iterable<Item> index() { return service.list(); }
Service @Service public class ItemService { @Autowired private ItemRepository repository;
public void create(Item item) { repository.save(item); }
Repository public interface ItemRepository { Item save(Item item); Iterable<Item> findAll();
Optional<Item> findById(String id); void deleteById(String id); }
ビルド
Gradle plugins plugins { id 'java' id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0' id 'org.graalvm.buildtools.native' version '0.9.18' }
bootBuildImage タスク Spring Boot Plugin のタスク Cloud Native Buildpacks を利用してビルド
ソースコードからビルド構成を検知 Native BuildTools プラグインがある時Native Build
bootBuildImage ./gradlew bootBuildImage --imageName spring-boot-3:latest docker push ...
潤沢なメモリが必要 自分のローカルマシンだとOOME 今回はAWS CodeBuild を利用してビルド 15 GB メモリ、8 vCPU のインスタンス
問題なく動いたか?
問題 - CASE 1 - DB アクセスにサードパーティライブラリを利用 spring-data-dynamodb dependencies {
implementation 'com.github.derjust:spring-data-dynamodb:5.1.0' }
Bean 生成エラー( 実行時エラー)
原因 - CASE 1 - AWS SDK for Java は
v2 以降からNativeImage に対応 該当ライブラリはv1 にしか対応していなかった
対策 - CASE 1 - 公式のdynamodb-enhanced を利用 dependencies { implementation
'software.amazon.awssdk:dynamodb' implementation 'software.amazon.awssdk:dynamodb-enhanced' }
対策 - CASE 1 - Bean とDynamoDB Table のマッピングを生成 @Bean
DynamoDbTable<Item> itemTable(DynamoDbEnhancedClient client) { return client.table("Items", TableSchema.fromBean(Item.class)); }
対策 - CASE 1 - Repository を独自実装 @Component public class
ItemRepositoryImpl implements ItemRepository { @Autowired private DynamoDbTable<Item> table; @Override public Item save(Item item) { table.putItem(item); return item; }
問題 - CASE 2 - Bean 生成エラー( 実行時エラー)
原因 - CASE 2 - dynamodb-enhanced も一部非対応
対策 - CASE 2 - StaticTableSchema を利用 private TableSchema<Item> getStaticTableSchema()
{ return StaticTableSchema.builder(Item.class) .newItemSupplier(Item::new) .addAttribute(String.class, a -> a.name("id").setter(Item::se .addAttribute(String.class, a -> a.name("name").setter(Item:: .addAttribute(String.class, a -> a.name("code").setter(Item:: .build(); }
成功!
性能比較
イメージサイズ plane: 17-jdk-alpine 上にbootJar を配備 220MB ⇒ 43MB に改善
メモリ使用量
起動速度 - bootJar - 起動時間: 14.354s
起動速度 - native - 起動時間: 0.596s
まとめ SpringBoot の起動時間は高速になる メモリ使用量は今回は参考程度 あまり負荷もかけていない イメージサイズの節約も嬉しい
課題 ライブラリがNative 対応してるか調査コストが高い 実行時エラーになるので確認に時間がかかる いい調査方法をご存知の方は教えて下さい
ありがとうございました