Skip to content

Latest commit

ย 

History

History
42 lines (28 loc) ยท 995 Bytes

Configuration_๋ถ„๋ฆฌ.md

File metadata and controls

42 lines (28 loc) ยท 995 Bytes

์—ฌ๋Ÿฌ ๊ฐœ์˜ @Configuration(์„ค์ • ํŒŒ์ผ)์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

๋นˆ์˜ ์ˆ˜๊ฐ€ ๋งŽ์•„์ง€๋ฉด ํ•œ ๋ˆˆ์— ์•Œ์•„๋ณด๊ธฐ ๋ณต์žกํ•ด์ง„๋‹ค.

์ด ๊ฒฝ์šฐ ์˜์—ญ๋ณ„(์—ญํ• ๋ณ„)๋กœ ์„ค์ •ํŒŒ์ผ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ด€๋ฆฌํ•˜๋ฉด ์ข‹๋‹ค.

์ด๋ฅผ ์œ„ํ•ด ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์กด์žฌํ•œ๋‹ค.

1. ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ(ApplicationContext) ์ƒ์„ฑ ์‹œ ์ถ”๊ฐ€ ์ „๋‹ฌ

AnnotationConfigApplicationContext context = 
    new AnnotationConfigApplicationContext(Conf.class, Conf2.class);

2. @Import ์–ด๋…ธํ…Œ์ด์…˜ ์‚ฌ์šฉ

์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜๋‚˜์˜ ์„ค์ • ํŒŒ์ผ์ด ๋‹ค๋ฅธ ์„ค์ • ํŒŒ์ผ๋“ค์„ ํฌํ•จํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค.

@Configuration
@Import(Conf2.class)
public class Conf {
    ...
}

์—ฌ๋Ÿฌ ๊ฐœ์˜ ์„ค์ • ํŒŒ์ผ์„ ํฌํ•จํ•  ๊ฒฝ์šฐ ๋ฐฐ์—ด์„ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

@Configuration
@Import({ Conf2.class, Conf3.class })
public class Conf {
    ...
}

์ถœ์ฒ˜