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
71
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
決済サービスのSpring Bootのバージョンを2系に上げた話
b1a9id
0
140
Form認証で学ぶSpring Security入門
b1a9id
0
280
パラレルキャリアがもたらす相乗効果
b1a9id
1
1.2k
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
b1a9id
0
1.5k
ユニットテストのアサーション 流れるようなインターフェースのAssertJを添えて 入門者仕立て
b1a9id
1
120
Spring超入門-Springと出会ってから1年半-
b1a9id
1
73
Other Decks in Programming
See All in Programming
定理証明プラットフォーム lapisla.net
abap34
1
1.8k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
120
Rubyで始める関数型ドメインモデリング
shogo_tksk
0
110
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
330
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
120
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
270
仕様変更に耐えるための"今の"DRY原則を考える / Rethinking the "Don't repeat yourself" for resilience to specification changes
mkmk884
2
400
Lottieアニメーションをカスタマイズしてみた
tahia910
0
130
WebDriver BiDiとは何なのか
yotahada3
1
140
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
560
動作確認やテストで漏れがちな観点3選
starfish719
6
1k
SwiftUI Viewの責務分離
elmetal
PRO
1
240
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.2k
Statistics for Hackers
jakevdp
797
220k
A Philosophy of Restraint
colly
203
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
960
Building Applications with DynamoDB
mza
93
6.2k
Adopting Sorbet at Scale
ufuk
74
9.2k
RailsConf 2023
tenderlove
29
1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
9
450
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Bootstrapping a Software Product
garrettdimon
PRO
306
110k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
How to Ace a Technical Interview
jacobian
276
23k
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のマッピング情報
スピーカー交代