Study/Spring

์ปดํฌ๋„ŒํŠธ ์Šค์บ” ์Šคํ”„๋ง์€ ์„ค์ • ์ •๋ณด๊ฐ€ ์—†์–ด๋„ ์ž๋™์œผ๋กœ ์Šคํ”„๋ง ๋นˆ์„ ๋“ฑ๋กํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ ์Šค์บ”์ด๋ผ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. @Configuration @ComponentScan( excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = Configuration.class)) public class AutoAppConfig { } ์ปดํฌ๋„ŒํŠธ ์Šค์บ”์€ ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ @Component ์• ๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ํด๋ž˜์Šค๋ฅผ ์Šค์บ”ํ•ด์„œ ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•œ๋‹ค. ์ด๋•Œ ์Šคํ”„๋ง ๋นˆ์˜ ๊ธฐ๋ณธ ์ด๋ฆ„์€ ํด๋ž˜์Šค๋ช…์„ ์‚ฌ์šฉํ•˜๋˜ ๋งจ ์•ž๊ธ€์ž๋งŒ ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋นˆ ์ด๋ฆ„ ๊ธฐ๋ณธ ์ „๋žต: MemberServiceImpl ํด๋ž˜์Šค -> memberServiceImpl ๋นˆ ์ด๋ฆ„ ์ง์ ‘ ์ง€์ •: ๋งŒ์•ฝ ์Šคํ”„๋ง ๋นˆ์˜ ์ด๋ฆ„์„..
์‹ฑ๊ธ€ํ†ค ํŒจํ„ด ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋”ฑ 1๊ฐœ๋งŒ ์ƒ์„ฑ๋˜๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•˜๋Š” ๋””์ž์ธ ํŒจํ„ด private ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์™ธ๋ถ€์—์„œ ์ž„์˜๋กœ new ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๋„๋ก ๋ง‰๊ณ  getInstance ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•ด์„œ ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋ฅผ return ํ•œ๋‹ค. ์ฃผ์˜์  : ์—ฌ๋Ÿฌ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ํ•˜๋‚˜์˜ ๊ฐ™์€ ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋ฅผ ๊ณต์œ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‹ฑ๊ธ€ํ†ค ๊ฐ์ฒด๋Š” statefulํ•˜๊ฒŒ ์„ค๊ณ„ํ•˜๋ฉด ์•ˆ๋œ๋‹ค. ๋ฌธ์ œ์  ์‹ฑ๊ธ€ํ†ค ํŒจํ„ด์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ ์ž์ฒด๊ฐ€ ๋งŽ์ด ๋“ค์–ด๊ฐ„๋‹ค ์ž์‹ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ธฐ ์–ด๋ ต๋‹ค ์œ ์—ฐ์„ฑ์ด ๋–จ์–ด์ง„๋‹ค ์˜์กด๊ด€๊ณ„์ƒ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๊ตฌ์ฒด ํด๋ž˜์Šค์— ์˜์กด - DIP ์œ„๋ฐ˜ ๋”๋ณด๊ธฐ ์˜์กด๊ด€๊ณ„ ์—ญ์ „ ์›์น™ : DIP, Dependency inversion principle ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์ถ”์ƒํ™”์— ์˜์กดํ•ด์•ผ์ง€, ๊ตฌ์ฒดํ™”์— ์˜์กดํ•˜๋ฉด ์•ˆ๋œ๋‹ค. ๊ตฌํ˜„ ํด๋ž˜์Šค์— ์˜์กดํ•˜์ง€ ๋ง๊ณ ..
์Šคํ”„๋ง์ด ๋‹ค์–‘ํ•œ ์„ค์ • ํ˜•์‹์„(Annotation, xml, etc..) ์ง€์›ํ•  ์ˆ˜ ์žˆ๋Š” ์ด์œ  ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๋Š” ๋ฉ”ํƒ€์ •๋ณด(beanDefinition)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์Šคํ”„๋ง ๋นˆ์„ ์ƒ์„ฑํ•œ๋‹ค. XML์„ ์ฝ์–ด์„œ BeanDefinition์„ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค. ์ž๋ฐ” ์ฝ”๋“œ๋ฅผ ์ฝ์–ด์„œ BeanDefinition์„ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค. ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๋Š” ์ž๋ฐ” ์ฝ”๋“œ์ธ์ง€, XML์ธ์ง€ ๋ชฐ๋ผ๋„ ๋œ๋‹ค. ์˜ค์ง BeanDefinition๋งŒ ์•Œ๋ฉด ๋œ๋‹ค. ๐Ÿ“Œ ์ƒˆ๋กœ์šด ํ˜•์‹์˜ ์„ค์ • ์ •๋ณด๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด, XxxBeanDefinitionReader๋ฅผ ๋งŒ๋“ค์–ด์„œ BeanDefinition์„ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค. BeanDefinition BeanClassName: ์ƒ์„ฑํ•  ๋นˆ์˜ ํด๋ž˜์Šค ๋ช…(์ž๋ฐ” ์„ค์ • ์ฒ˜๋Ÿผ ํŒฉํ† ๋ฆฌ ์—ญํ• ์˜ ๋นˆ์„ ์‚ฌ์šฉํ•˜๋ฉด ์—†์Œ) factoryBeanName: ํŒฉํ† ..
BeanFactory์™€ ApplicationContext BeanFactory : ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์˜ ์ตœ์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค. getBean() ์ œ๊ณต ApplicationContext BeanFactory์˜ ๊ธฐ๋Šฅ์„ ๋ชจ๋‘ ์ƒ์†๋ฐ›์•„์„œ ์‚ฌ์šฉ ์–ดํ”Œ๋ฆฌ์บ์ด์…˜์„ ๊ฐœ๋ฐœํ•  ๋•Œ ๋นˆ์„ ๊ด€๋ฆฌํ•˜๊ณ  ์กฐํšŒํ•˜๋Š” ๊ธฐ๋Šฅ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ˆ˜ ๋งŽ์€ ๋ถ€๊ฐ€๊ธฐ๋Šฅ์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค ๋ฉ”์‹œ์ง€ ์†Œ์Šค๋ฅผ ํ™œ์šฉํ•œ ๊ตญ์ œํ™” ๊ธฐ๋Šฅ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฒคํŠธ ํŽธ๋ฆฌํ•œ ๋ฆฌ์†Œ์Šค ์กฐํšŒ ๊ทธ ์™ธ์˜ ์ฐจ์ด์  Lazy Loading(BeanFactory) vs. Eager Loading(ApplicationContext) BeanFactory loads beans on-demand, while ApplicationContext loads all beans at star..
์Šคํ”„๋ง ๋นˆ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ์ฒด In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. - the Spring Framework documentation ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋ก๋œ ๋ชจ๋“  ๋นˆ ์กฐํšŒ ๋ชจ๋“  ๋นˆ ์ถœ๋ ฅํ•˜๊ธฐ @Test @DisplayName("๋ชจ๋“  ๋นˆ ์ถœ๋ ฅํ•˜๊ธฐ") void findAllBean(){ String[] beanDefiniti..
YURI๐Ÿ•๐Ÿ“๐Ÿถ
'Study/Spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (4 Page)