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超入門-Springと出会ってから1年半-
Search
Ryosuke Uchitate
December 03, 2016
Programming
1
82
Spring超入門-Springと出会ってから1年半-
JJUG CCC 2016 Fall(2016/12/3)
Ryosuke Uchitate
December 03, 2016
Tweet
Share
More Decks by Ryosuke Uchitate
See All by Ryosuke Uchitate
キャッシュレス決済のプロダクトから決済基盤への進化
b1a9id
0
390
決済サービスのSpring Bootのバージョンを2系に上げた話
b1a9id
0
150
Form認証で学ぶSpring Security入門
b1a9id
0
340
パラレルキャリアがもたらす相乗効果
b1a9id
1
1.3k
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
b1a9id
0
1.7k
ユニットテストのアサーション 流れるようなインターフェースのAssertJを添えて 入門者仕立て
b1a9id
1
140
Spring starterによるSpring Boot Starter
b1a9id
1
83
Other Decks in Programming
See All in Programming
CSC307 Lecture 01
javiergs
PRO
0
650
はじめてのカスタムエージェント【GitHub Copilot Agent Mode編】
satoshi256kbyte
0
140
脳の「省エネモード」をデバッグする ~System 1(直感)と System 2(論理)の切り替え~
panda728
PRO
0
130
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
1
850
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.5k
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
310
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
230
AIエージェントの設計で注意するべきポイント6選
har1101
6
2.9k
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
GoLab2025 Recap
kuro_kurorrr
0
1.1k
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
1.1k
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
160
Featured
See All Featured
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
110
Prompt Engineering for Job Search
mfonobong
0
140
Information Architects: The Missing Link in Design Systems
soysaucechin
0
730
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
94
End of SEO as We Know It (SMX Advanced Version)
ipullrank
2
3.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
The Pragmatic Product Professional
lauravandoore
37
7.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
Site-Speed That Sticks
csswizardry
13
1k
Darren the Foodie - Storyboard
khoart
PRO
1
2.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
Transcript
Spring超入門 -Springと出会ってから1年半-
mi presento ▪名前:内立良介(うちたてりょうすけ) ▪あだ名:ジェンダ・フリ男 男性と女性の狭間(性格的な意味で) ▪趣味:ファッション・パン屋巡り 靴に夢中・クロワッサン ▪特技:バスケ 初めてから15年くらい? ▪所属:Tagbangers
通称タグバン
Tagbangers ▪場所:横浜市神奈川区 最寄りは横浜駅(徒歩15分) ▪社則 業務時間・交通費・通勤費・給与の4つのみ ▪飲み会 社長いじり ▪勉強会:TAG BAR 初回からちょうど1年
AGENDA 1. 今回作ったWebアプリケーションの紹介 2. Springについて 3. ソースコードの解説 4. おまけ
1.今回作ったWebアプ リケーションの紹介
利用者管理アプリ • 新規登録機能 • 編集機能 • 一覧表示機能 • 削除機能
新規登録機能の 構成図
None
え?
ビジネスロジックって よく聞くけど何だ?
訳すと、業務の論理?
ビジネスロジックは、データベースとユーザ ーインタフェース間の情報のやりとりを制御 する手順といったようなものを指す(技術的 でない)用語である。(Wikipediaより)
一言で言うと
システム固有の お仕事部分
具体例 • 画面から商品単価入力すると、税込でDBに登録す る処理 • 電話番号が「1234567」ではなく「123-4567」の フォーマットで入力されているかのチェックする処 理
よし、スッキリ!次
2.Springについて
Springって何? • Javaのフレームワーク • DI(依存性の注入)はとても重要 • さまざまなプロジェクト
え?(本日2回目)
DI(Dependency Injection):依存性の注入
意味わからん
DI • DIとは、Springが管理しているインスタンスの Beanをちょうだいとお願いしてDIコンテナから該 当箇所に注入してもらうこと DIコンテナ (Beanを管理している箱) Bean Bean Bean
Bean UserCreateController.java Beanちょうだい Bean
Bean:豆
え?
豆ってどういうこと?
調べて見ると、 コーヒー豆からきてるっぽ い
Java(ジャワ) • ジャワコーヒーはインドネシアのジャ ワ島を産地とするコーヒー豆。( WikiPediaより)
Beanも日本語訳は無 視
アドバイス
日本語訳に とらわれ過ぎない
さらにもう1つ
アノテーション=注釈 って訳さない方がよい
コメントとの違い何? ってなりました
経験談はこれくらいで 次
Spring Bootとは?
Spring Boot-1- • Spring Frameworkでアプリケーションを簡単に作 るための仕組み • 2014年4月にver1.0がリリースで1.4.2が最新 • XMLやJavaConfigでのBean定義、ログの設定など
が不要
Spring Boot-2- • mavenに限って言えば、pom.xmlに書くだけで依存 関係を解決してくれる • 良くも悪くもどういう動きをしているかよく知らな くてもそれなりに堅牢なアプリは作れる
どれくらい簡単かと 言うと
Spring Initializrでぽちぽちすれば、 基本設定で構築されたプロジェク トを作ることができる
Spring Initialize?
Spring Initializr https://start.spring.io/
Spring Bootの 重要な仕組み
AutoConfigure • Springが提供しているプロジェクトやOSSを利用す る時に必要なBean定義をSpring Bootが自動で行っ てくれる仕組みのこと 面倒なセットアップや設定がほとんど不要になる pom.xmlに書いたものを Bean登録する処理など
自動設定を有効にするには? @SpringBootApplication public class Application { public static void main(String[]
args) { SpringApplication.run(Application.class, args); } } このクラスに@Configurationを付与する
でも、、、
@Configurationないじゃん! @SpringBootApplication public class Application { public static void main(String[]
args) { SpringApplication.run(Application.class, args); } }
@SpringBootApplication に含まれている
はず。でも、、、
@Configurationないじゃん! @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFilters = @Filter(type
= FilterType.CUSTOM, classes = TypeExcludeFilter.class)) public @interface SpringBootApplication { あやしい
見つけた! @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration public @interface SpringBootConfiguration {
@SpringBootApplicationは3 つのアノテーションを 1つにまとめたもの
@SpringBootApplication • @EnableAutoConfiguration • 自動設定を有効にする • @ComponentScan • このパッケージ配下で@Component、 @Service、@Controller、@RestController、
@Namedが付与されているクラスをDIコンテ ナに登録する • @SpringBootConfiguration • このクラス自体をBean定義可能にする
自動設定が有効に なるまでの流れ
1.DIコンテナ(ApplicationContext)作成
2.BeanFactory作成
3.spring.factories読込、 BeanDefinition取捨選択、並び替え
4.Bean登録
3.ソースコードの解説
pom.xml •プロジェクトに関する情報が書かれている •使いたいstarterやOSSの情報をかくとをレポジトリ から取ってくる <dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
... </dependencies>
@Controller •Controllerだよって教える •これを書くとSpring Bootで自動設定の対象となって Bean登録される
@RequestMapping •create.htmlのactionで指定したパスに一致している パスにマッピングされる •Spring Boot 1.4からは@GetMappingや @PostMapping、@DeleteMappingなども登場して いる @GetMapping =
@RequestMapping(method = RequestMethod.GET)
@Validated •formの入力値チェックをしてもらいたいときにつけ る @PostMapping public String save( @Validated @ModelAttribute(name =
FORM_MODEL_KEY) UserCreateForm form, BindingResult errors, RedirectAttributes redirectAttributes) {
formの中にformがある ときのエラーチェック
UserCreateForm.java @Getter @Setter public class UserCreateForm implements Serializable { @NotNull
private String name; private Integer age; @NotNull private Gender gender; @Valid private AddressForm address; public UserCreateRequest toUserCreateRequest() { return new UserCreateRequest(getName(), getAge(), getGender(), Address.generateAddress(getAddress())); } } @ValidをつけるとFormのなかの Formの入力値チェックをする
Springに思う事
神ってる
おわり