Spring Container

์Šคํ”„๋ง์˜ ํ•ต์‹ฌ!

DI (์˜์กด์„ฑ ์ฃผ์ž…)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌ์„ฑํ•˜๋Š” Bean (๊ฐ์ฒด)๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค

์œ ํ˜•

BeanFactory

Bean์„ ์‚ฌ์šฉํ•  ๋•Œ ๋กœ๋”ฉ (Lazy-loading)

  • Bean ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” class

  • Bean์„ ์ƒ์„ฑํ•˜๊ณ , ์กฐํšŒํ•˜๊ณ  ๋Œ๋ ค์ฃผ๋Š” ๋“ฑ Bean์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋‹ด๋‹นํ•œ๋‹ค

  • Bean Factory๋Š” Bean์˜ ์ •์˜๋ฅผ ์ฆ‰์‹œ ๋กœ๋”ฉํ•˜์ง€๋งŒ, Bean ์ž์ฒด๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๊นŒ์ง€๋Š” ์ธ์Šคํ„ด์Šคํ™” ํ•˜์ง€ ์•Š๋Š”๋‹ค

    • getBean() ์ด ํ˜ธ์ถœ๋˜๋ฉด, ๊ทธ ๋•Œ์„œ์•ผ Factory๊ฐ€ ์˜์กด์„ฑ ์ฃผ์ž… (DI)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ›์€ Bean์„ ์ธ์Šคํ„ด์Šคํ™” ํ•˜๊ณ , Bean์˜ ํŠน์„ฑ์„ ์„ค์ •ํ•œ๋‹ค โ†’ On-demand ๋ฐฉ์‹

  • Bean์„ ์ƒ์„ฑํ•˜๊ณ , ๊ด€๊ณ„๋ฅผ ์„ค์ •ํ•˜๋Š” IoC์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์— ์ดˆ์ ์ด ๋งž์ถฐ์ ธ ์žˆ๋‹ค

  • Bean์„ ์ƒ์„ฑํ•˜๊ณ  ๋กœ๋”ฉํ•˜๋Š” ๋ฐฉ์‹

    • BeanFactory ๋Š” Lazy-loading ์„ ํ•œ๋‹ค

    • Method๋‚˜ class๊ฐ€ Bean loading ์š”์ฒญ์„ ๋ฐ›๋Š” ์‹œ์ ์— ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋กœ๋”ฉํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค

      • ๊ทธ๋ž˜์„œ .getBean() method์— ์˜ํ•ด ์š”์ฒญ์„ ๋ฐ›๋Š” ์‹œ์ ์— ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋กœ๋“œ๋œ๋‹ค

ApplicationContext

๋Ÿฐํƒ€์ž„ ์‹คํ–‰ ์‹œ ๋ชจ๋“  Bean์„ ๋กœ๋”ฉ (Pre-loading)

  • BeanFactory์™€ ์œ ์‚ฌํ•˜์ง€๋งŒ, ๋” ํ–ฅ์ƒ๋œ ํ˜•ํƒœ์˜ ์ปจํ…Œ์ด๋„ˆ๋‹ค

  • ๋ณ„๋„์˜ ์ •๋ณด๋ฅผ ์ฐธ๊ณ ํ•ด์„œ Bean์˜ ์ƒ์„ฑ, ๊ด€๊ณ„ ์„ค์ • ๋“ฑ์˜ ์ œ์–ด๋ฅผ ์ด๊ด„ํ•˜๋Š” ๊ฒƒ์— ์ดˆ์ ์„ ๋งž์ถ”๊ณ  ์žˆ๋‹ค

  • Bean์„ ์ƒ์„ฑํ•˜๊ณ  ๋กœ๋”ฉํ•˜๋Š” ๋ฐฉ์‹

    • ApplicationContext ๋Š” Pre-loading ์„ ํ•œ๋‹ค

    • ๋ชจ๋“  Bean๋“ค๊ณผ ์„ค์ • ํŒŒ์ผ๋“ค์ด ApplicationContext์— ์˜ํ•ด ๋กœ๋“œ ์š”์ฒญ์ด ๋  ๋•Œ ์ธ์Šคํ„ด์Šค๋กœ ๋งŒ๋“ค์–ด์ง€๊ณ , ๋กœ๋“œ๋œ๋‹ค

BeanFactory ์™€ ApplicationContext

  • ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง„ ์ด์œ ๋Š” ์‚ฌ์šฉ ๋นˆ๋„์™€ ์‚ฌ์šฉ๋˜๋Š” ์ž์›์˜ ๊ด€๊ณ„ ๋•Œ๋ฌธ์ด๋‹ค

    • ์ž์ฃผ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” Bean์ด๋ผ๋ฉด ์†Œ๋ชจ๋˜๋Š” ์ž์›์„ ์•„๋ผ๊ธฐ ์œ„ํ•ด ์‹ค์ œ ์š”์ฒญ ์‹œ์—๋งŒ ๋กœ๋”ฉํ•˜๊ณ  (Lazy-loading) โ†’ BeanFactory ์‚ฌ์šฉ

    • ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” Bean์ด๋ผ๋ฉด ํ•œ ๋ฒˆ์— ๋กœ๋“œํ•˜๋Š” ๊ฒƒ (Pre-loading)์ด ์ข‹๋‹ค โ†’ ApplicationContext ์‚ฌ์šฉ

Last updated