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
Spring starterによるSpring Boot Starter
Search
Ryosuke Uchitate
June 22, 2016
Programming
1
77
Spring starterによるSpring Boot Starter
JSUG勉強会 2016年その4 Spring I/O報告会(2016/6/22)
Ryosuke Uchitate
June 22, 2016
Tweet
Share
More Decks by Ryosuke Uchitate
See All by Ryosuke Uchitate
キャッシュレス決済のプロダクトから決済基盤への進化
b1a9id
0
260
決済サービスのSpring Bootのバージョンを2系に上げた話
b1a9id
0
150
Form認証で学ぶSpring Security入門
b1a9id
0
310
パラレルキャリアがもたらす相乗効果
b1a9id
1
1.2k
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
b1a9id
0
1.6k
ユニットテストのアサーション 流れるようなインターフェースのAssertJを添えて 入門者仕立て
b1a9id
1
120
Spring超入門-Springと出会ってから1年半-
b1a9id
1
79
Other Decks in Programming
See All in Programming
Gleamという選択肢
comamoca
6
760
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.3k
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
230
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
380
エンジニア向け採用ピッチ資料
inusan
0
160
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
型付きアクターモデルがもたらす分散シミュレーションの未来
piyo7
0
810
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
260
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
FormFlow - Build Stunning Multistep Forms
yceruto
1
190
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
53
7.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Adopting Sorbet at Scale
ufuk
77
9.4k
The Invisible Side of Design
smashingmag
299
51k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
How GitHub (no longer) Works
holman
314
140k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
Why Our Code Smells
bkeepers
PRO
337
57k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
Gamification - CAS2011
davidbonilla
81
5.3k
Transcript
Boot starterが語るSpring bootの仕組み & Spring 5以降のReactiveな流れと フロントまわりの話 株式会社タグバンガーズ
横浜・設立6年目・Webアプリ開発・ほぼSpring案件
TAG BAR 月1ぐらい開催してる社外の方を招いて行う勉強会 connpass(http://tagbar.connpass.com/)にて募集
軽く自己紹介 佐々木 亜里沙(ささき ありさ) UIチーム・プロダクトチーム 北海道 内立 良介(うちたて りょうすけ) デベロップメントチーム
宮崎
Spring starterによる Spring Boot Starter 株式会社タグバンガーズ 内立良介
AGENDA Spring I/O 2016の様子 セッション概要 セッションの解釈(@AutoConfiguration, Starter) 開発時の便利機能の紹介
Spring I/O 2016 開催地:スペイン・バルセロナ セッション数:2日間で48セッション 参加者:26カ国、475人(うち日本からの参加:8人)
Session
AFTER EVENT PARTY
セッションの概要
CUSTOMIZE YOUR SPRING BOOT EXPERIENCE BY WRITING YOUR OWN SPRING
BOOT STARTER https://github.com/michael-simons/springio2016 ベースとなるセッション
Custom Spring Boot Starter –part1- Spring Boot Starterには様々な種類がある Integration、Template Engines、Validationなど
プロジェクトを作るときは以下のURLから作ると簡単に作れる http://start.spring.io
None
Custom Spring Boot Starter –part2- 標準的なAutoConfigurationに使用 @ConditionalOnClass @AutoConfigureAfter、@AutoConfigureBefore @Bean
Custom Spring Boot Starter –part3- その他の条件指定・順序決め @ConditionalOnProperty @ConditionalOnMissingBean @Order
セッションの解釈
@SpringBootApplicationって何者?
@SpringBootApplication 3つのアノテーションを1つにまとめたもの @EnableAutoConfiguration 自動設定を有効にする @ComponentScan このクラスのパッケージ配下で@Component, @Service, @Controller,@RestController, @NamedつきのクラスをDIコンテナに登録する @Configuration
このクラス自体をBean定義可能にする
@SpringBootApplicationの流れ (@EnableAutoConfigurationのみ)
1.DIコンテナ(ApplicationContext)作成
2.BeanFactory作成
3.spring.factries読込、 BeanDefinition取捨選択、並び替え
4.Bean登録
さあ、starterを作りましょう!!!
starterがやってくれること アプリケーションの開発に必要な依存関係を追加 ライブラリを使うために必要な設定を追加
ネーミングルール ”spring-boot”ではじまる名前をつけてはいけない!
社内で作ったライブラリなどを starterにすれば。。。
面倒な設定なしに使える!!
突然ですが、 spring.factriesって知ってますか?
spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration= com.mycorp.libx.autoconfigure.LibXAutoConfiguration, com.mycorp.libx.autoconfigure.LibXWebAutoConfiguration このように書けば、Spring Bootが@EnableAutoConfigurationの対象と認識してくれ る。 デフォルトのパスは、META-INF/spring.factoriesとなっている。
作ったstarterを読み込ませたいなら
作ったstarterのAutoConfigurationのパスを META-INF/spring.factoriesに書けばいい。
というのはわかったけど。。。
依存関係があるから適用する 順序を指定したい。
安心してください! 順序指定できますよ!
インポート順序を指定するための アノテーション @Order 引数に指定した順序で優先順位が決まる。最も小さい値が優先度が最も高 い。 @AutoConfigureBefore 指定したauto-configurationクラスより前に適用する。 @AutoConfigureAfter 指定したauto-configurationクラスより後に適用する。
依存関係にあるクラスの有無で インポートするかどうか指定したい。
安心してください! 指定できますよ!
Conditionアノテーションを使おう!
Conditonアノテーション @ConditionalOnClass(@ConditionalOnMissingClass) 指定したクラスがクラスパス上にあったら(なかったら)有効 @ConditionalOnBean(@ConditionalOnMissingBean) 指定したBeanがあったら(なかったら)有効 @ConditionalOnProperty 指定したプロパティがあったら有効
@ConditionalOnResource 指定したリソースがあったら有効 @ConditionalOnWebApplication(@ConditionalOnNotWebApplication) Webアプリケーションであったら(なかったら)有効
デモアプリケーションをみてみよう!!
テンプレートで <banner:show />を指定すれば、 viewでbannerイメージを表示して くれるstarter セッションで行われたデモ
プロジェクトの構成
demoの pom.xml
AutoConfigurationクラス
spring.factories
開発時の便利機能の紹介
spring-boot-starter-actuator システムの状態やメトリクスを確認できる 主なエンドポイント autoconfig auto-configurationの候補と自動設定された理由・されなかった理由 beans DIコンテナに登録されているBeanの一覧 metrics
メトリクス情報が見れる mappings @RequestMappingのマッピング情報
スピーカー交代