๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[Spring] Component Scan๊ณผ Function์„ ์‚ฌ์šฉํ•œ ๋นˆ ๋“ฑ๋ก ๋ฐฉ๋ฒ• [Spring] Component Scan๊ณผ Function์„ ์‚ฌ์šฉํ•œ ๋นˆ ๋“ฑ๋ก ๋ฐฉ๋ฒ• 1. @ComponentScan @ComponentScan ์• ๋…ธํ…Œ์ด์…˜์€ spring 3.1๋ถ€ํ„ฐ ๋„์ž…๋์œผ๋ฉฐ ์„ค์ •๋œ ์‹œ์ž‘ ์ง€์ ๋ถ€ํ„ฐ ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค๋ฅผ scanningํ•˜์—ฌ ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค๋Š” ๋‹ค์Œ ์• ๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ํด๋ž˜์Šค๋ฅผ ์˜๋ฏธํ•œ๋‹ค. @Component @Repository @Service @Controller @Configuration @ComponentScan์˜ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋‘ ๊ฐ€์ง€ ์†์„ฑ์€ component๋ฅผ scanํ•  ์‹œ์ž‘ ์ง€์ ์„ ์„ค์ •ํ•˜๋Š” ์†์„ฑ๊ณผ scanํ•œ component ์ค‘ ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•˜์ง€ ์•Š์„ ํด๋ž˜์Šค๋ฅผ ์ œ์™ธํ•˜๋Š” ํ•„ํ„ฐ ์†์„ฑ์ด๋‹ค. 1) Scan ์‹œ์ž‘ ์ง€์  ์„ค์ • - basePackages()์™€.. 2020. 3. 2.
[Spring] ์Šคํ”„๋ง ๋นˆ(Bean)์˜ ๊ฐœ๋…๊ณผ ์ƒ์„ฑ ์›๋ฆฌ [Spring] ์Šคํ”„๋ง ๋นˆ(Bean)์˜ ๊ฐœ๋…๊ณผ ์ƒ์„ฑ ์›๋ฆฌ ๋นˆ(Bean) Spring IoC ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์ž๋ฐ” ๊ฐ์ฒด๋ฅผ ๋นˆ(Bean)์ด๋ผ๋Š” ์šฉ์–ด๋กœ ๋ถ€๋ฅธ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ new ์—ฐ์‚ฐ์ž๋กœ ์–ด๋–ค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ–ˆ์„ ๋•Œ ๊ทธ ๊ฐ์ฒด๋Š” ๋นˆ์ด ์•„๋‹ˆ๋‹ค. ApplicationContext.getBean()์œผ๋กœ ์–ป์–ด์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ์ฒด๋Š” ๋นˆ์ด๋‹ค. ์ฆ‰ Spring์—์„œ์˜ ๋นˆ์€ ApplicationContext๊ฐ€ ์•Œ๊ณ ์žˆ๋Š” ๊ฐ์ฒด, ์ฆ‰ ApplicationContext๊ฐ€ ๋งŒ๋“ค์–ด์„œ ๊ทธ ์•ˆ์— ๋‹ด๊ณ ์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ์–ด๋–ป๊ฒŒ Spring IoC ์ปจํ…Œ์ด๋„ˆ์— ๋นˆ์„ ๋“ฑ๋กํ• ๊นŒ? ๋นˆ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์–‘ํ•˜์ง€๋งŒ ๊ธฐ๋ณธ์ ์œผ๋กœ ํฌ๊ฒŒ ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. โ‘  Component Scanning โ‘ก ๋นˆ ์„ค์ •ํŒŒ์ผ์— ์ง์ ‘ ๋นˆ์„ ๋“ฑ๋ก Component Scan @Comp.. 2020. 2. 28.