[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. ์ด์ 1 ๋ค์