๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

4. IoC ์ปจํ…Œ์ด๋„ˆ 4๋ถ€ : @Component์™€ ์ปดํฌ๋„ŒํŠธ ์Šค์บ”

์ปดํฌ๋„ŒํŠธ ์Šค์บ” ์ฃผ์š” ๊ธฐ๋Šฅ ์Šค์บ” ์œ„์น˜ ์„ค์ • @Configuration ์œผ๋กœ ๋“ฑ๋ก๋œ ํด๋ž˜์Šค์˜ ํŒจํ‚ค์ง€ ๋‚ด์—์„œ๋งŒ ๋นˆ์„ ์ฐพ์•„์„œ ๋“ฑ๋กํ•œ๋‹ค. @SpringBootApplication @SpringBootAplication๋Š” auto-configuration์„ ๋‹ด๋‹นํ•œ๋‹ค. application class์—์„œ extra configuration์„ ์ •์˜ํ•˜๊ฑฐ๋‚˜ component scan์„ ํ•ด์ค€๋‹ค. @SpringBootApplication ํ•˜๋‚˜๋งŒ์œผ๋กœ @EnableAutoConfiguration,@ComponentScan,@Configuration์„ธ ๊ฐ€์ง€ Annotation์„ ์‚ฌ์šฉํ•œ ๊ฒƒ๊ณผ ๊ฐ™์€ ๋™์ž‘์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•„ํ„ฐ : ์–ด๋–ค ์• ๋…ธํ…Œ์ด์…˜์„ ์Šค์บ” ํ• ์ง€ ๋˜๋Š” ํ•˜์ง€ ์•Š์„์ง€ @Component @Repository @Service @..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

๋นˆ์„ ๋“ฑ๋กํ•˜๊ณ  ์˜์กด์„ฑ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•

๋นˆ ์ด๋ž€? ์Šคํ”„๋ง IoC ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ด€๋ฆฌ ํ•˜๋Š” ๊ฐ์ฒด ์Šคํ”„๋ง IoC ์ปจํ…Œ์ด๋„ˆ๋ž€? BeanFactory ๋ฅผ ํ™•์žฅํ•˜๋Š” ApplicationContext๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ํ•˜๋Š” ์ผ : ๋นˆ ์„ค์ • ์†Œ์Šค๋กœ ๋ถ€ํ„ฐ ๋นˆ ์ •์˜๋ฅผ ์ฝ์–ด๋“ค์ด๊ณ , ๋นˆ์„ ๊ตฌ์„ฑํ•˜๊ณ  ์ œ๊ณตํ•œ๋‹ค. ( ๋นˆ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ, ์˜์กด ๊ด€๊ณ„ ์„ค์ •, ๋นˆ ์ œ๊ณต) ์žฅ์  1. ์˜์กด์„ฑ ๊ด€๋ฆฌ 2. ์Šค์ฝ”ํ”„ - ์‹ฑ๊ธ€ํ†ค (๊ธฐ๋ณธ๊ฐ’) : ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋งŒ ์‚ฌ์šฉ -> ๋น ๋ฅธ ์„ฑ๋Šฅ - ํ”„๋กœํ† ํƒ€์ž… : ๋งค๋ฒˆ ๋‹ค๋ฅธ ๊ฐ์ฒด 3. ๋ผ์ดํ”„์‚ฌ์ดํด ์ธํ„ฐํŽ˜์ด์Šค ๋นˆ ๋“ฑ๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ• ๋‘๊ฐ€์ง€ 1. ๊ณ ์ „์ ์ธ ๋ฐฉ์‹์˜ ๋นˆ ๋“ฑ๋ก ๋ฐฉ๋ฒ• - ApplicationContext (XML) ๋‹จ์  : ์ผ์ผํžˆ ํ•˜๋‚˜ํ•˜๋‚˜ ๋นˆ์„ ๋“ฑ๋กํ•ด์•ผ ํ•œ๋‹ค๋Š” ๋ถˆํŽธํ•จ์ด ์žˆ๋‹ค. 2. ์–ด๋…ธํ…Œ์ด์…˜์„ ์ด์šฉํ•œ ๋นˆ ๋“ฑ๋ก ๋ฐฉ๋ฒ• ( Java ) package ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

PSA( Portable Service Abstract )

PSA ๋ž€ ? ์ž˜ ๋งŒ๋“  ์ธํ„ฐํŽ˜์ด์Šค ๋‚˜์˜ ์ฝ”๋“œ ํ™•์žฅ์„ฑ์ด ์ข‹์ง€ ๋ชปํ•œ ์ฝ”๋“œ or ๊ธฐ์ˆ ์— ํŠนํ™”๋˜์–ด ์žˆ๋Š” ์ฝ”๋“œ ๋‚˜์˜ ์ฝ”๋“œ +++++++++ ์ž˜ ๋งŒ๋“  ์ธํ„ฐํŽ˜์ด์Šค(PSA) ++++++++++++++++ ํ™•์žฅ์„ฑ์ด ์ข‹์ง€ ๋ชปํ•œ ์ฝ”๋“œ or ๊ธฐ์ˆ ์— ํŠนํ™”๋˜์–ด ์žˆ๋Š” ์ฝ”๋“œ ์Šคํ”„๋ง ํŠธ๋žœ์žญ์…˜ @Transactional ์ด๋ผ๋Š” annotation์„ ์ฒ˜๋ฆฌํ•˜๋Š” Aspect ๊ฐ€ ์žˆ๋‹ค. ๊ทธ Aspect์—์„œ๋Š” *PlatformTransactionManager ๋ผ๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ฝ”๋”ฉ์„ ํ•ด๋†จ๋‹ค. * ์ž˜ ๋งŒ๋“  ์ธํ„ฐํŽ˜์ด์Šค(PSA) ์˜ ์˜ˆ ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— PlatformTransactionManager ์˜ ์—ฌ๋Ÿฌ ๊ตฌํ˜„์ฒด๋“ค์ด ๋ฐ”๋€Œ๋”๋ผ๋„, ํŠธ๋žœ์žญ์…˜์˜ Aspect ์ฝ”๋“œ๋Š” ๋ฐ”๋€Œ์ง€๊ฐ€ ์•Š๋Š”๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” Repository ๋ผ๋Š” interface๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

AOP (Aspect-Oriented Programming)

AOP ์˜ ํ•ต์‹ฌ : ํฉ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ํ•œ๊ณณ์œผ๋กœ ๋ชจ์œผ๋Š” ์ฝ”๋”ฉ ๊ธฐ๋ฒ• ํฉ์–ด์ง„ AAAA ์™€ BBBB class A { method a () { AAAA ์˜ค๋Š˜์€ 7์›” 4์ผ ๋ฏธ๊ตญ ๋…๋ฆฝ ๊ธฐ๋…์ผ์ด๋ž˜์š”. BBBB } method b () { AAAA ์ €๋Š” ์•„์นจ์— ์šด๋™์„ ๋‹ค๋…€์™€์„œ ๋ฐฅ๋จน๊ณ  ๋นจ๋ž˜๋ฅผ ํ–ˆ์Šต๋‹ˆ๋‹ค. BBBB } } class B { method c() { AAAA ์ ์‹ฌ์€ ์ด๊ฑฐ ์ฐ๋Š๋ผ ๋ชป๋จน์—ˆ๋Š”๋ฐ ์ €๋…์—” ์ œ์œก๋ณถ์Œ์„ ๋จน๊ณ  ์‹ถ๋„ค์š”. BBBB } } AAAA , BBBB ๋ฅผ ๋ฐ–์œผ๋กœ ๋นผ๋ฒ„๋ฆฐ๋‹ค. ๋ชจ์•„ ๋†“์€ AAAA ์™€ BBBB class A { method a () { ์˜ค๋Š˜์€ 7์›” 4์ผ ๋ฏธ๊ตญ ๋…๋ฆฝ ๊ธฐ๋…์ผ์ด๋ž˜์š”. } method b () { ์ €๋Š” ์•„์นจ์— ์šด๋™์„ ๋‹ค๋…€์™€์„œ ๋ฐฅ๋จน๊ณ  ๋นจ๋ž˜๋ฅผ ํ–ˆ์Šต๋‹ˆ๋‹ค. } } class B { method c..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

IoC (Inversion of Control) , DI (Dependency Injection)

IoC ๋ž€? Inversion of Control ( ์ œ์–ด๊ถŒ ์—ญ์ „ ) (IoC ์˜ˆ์‹œ) ๊ฐ์ฒด๋ฅผ ๋‚ด๊ฐ€ ์ง์ ‘ new ์ƒ์„ฑ (IoC ์ ์šฉ x) class OwnerController{ private OwnerRepository repository = new OwnerRepository(); } IoC ๋ฅผ ์ด์šฉํ•œ ์˜์กด์„ฑ ์ฃผ์ž… (IoC ์ ์šฉ o) class OwnerController{ private OwnerRepository repo; public OwnerController(OwnerRepository repo){ //์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๊ฐ์ฒด๋ฅผ ๋ฐ›๋Š”๋‹ค this.repo = repo; } } OwnerRepository๋Š” OwnerController์˜ ์˜์กด์„ฑ์ด๋‹ค. ->OwnerRepository๊ฐ€ ์žˆ์–ด์•ผ ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

๋นˆ (Bean) , IoC (Inversion of Control) ์ปจํ…Œ์ด๋„ˆ, @Autowired

IoC ์ปจํ…Œ์ด๋„ˆ - ApplicationContext ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋นˆ(bean)์ด๋ผ๊ณ  ํ•˜๊ณ , ์ด ๋นˆ(bean)๋“ค์„ ๊ด€๋ฆฌํ•œ๋‹ค๋Š” ์˜๋ฏธ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋นˆ ํŒฉํ† ๋ฆฌ(BeanFactory) ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. BeanFactory์— ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…์Šค(ApplicationContext)๋ผ๊ณ  ๋ถ€๋ฆ„ ApplcationContext : ์–˜๊ฐ€ Bean๋“ค์„ ๋งŒ๋“ค๊ณ , ๊ทธ Bean๋“ค์˜ ์˜์กด์„ฑ์„ ์—ฎ์–ด์ค€๋‹ค. ์˜ค๋กœ์ง€ Bean๋“ค๋งŒ ๊ด€๋ฆฌ! OwnerController ๊ฐ€ IoC ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ๋“ค์–ด์˜ค๊ณ , ์ปจํ…Œ์ด๋„ˆ์—์„œ OwnerController ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด ์ค€๋‹ค. ๊ทธ๋ฆฌ๊ณ , OwnerRepository ์˜ ๊ฐ์ฒด๋„ ๋งŒ๋“ค์–ด ์ค€๋‹ค. -> Bean ์ฆ‰, Bean๋“ค์˜ ์˜์กด์„ฑ๋“ค์„ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌํ•ด์ค€๋‹ค. I..

iseunghan
'๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (4 Page)