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
Immutable ActiveRecord
megane42
0
140
Lottieアニメーションをカスタマイズしてみた
tahia910
0
130
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
740
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
12
4.1k
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
130
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
570
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
560
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
110
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
Amazon Bedrock Multi Agentsを試してきた
tm2
1
290
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
370
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
Gamification - CAS2011
davidbonilla
80
5.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
How STYLIGHT went responsive
nonsquared
98
5.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Embracing the Ebb and Flow
colly
84
4.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
How to train your dragon (web standard)
notwaldorf
91
5.8k
For a Future-Friendly Web
brad_frost
176
9.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
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のマッピング情報
スピーカー交代