Home @Bean vs @Component
Post
Cancel

@Bean vs @Component

@Bean vs @Component

๐Ÿ˜ ๊ณตํ†ต์ 

Bean์„ ์ƒ์„ฑํ•˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜.

๐Ÿ˜ต ์ฐจ์ด์ 

@Bean ์–ด๋…ธํ…Œ์ด์…˜์˜ docs๋ฅผ ๊ฐ€๋ณด๋ฉด ElementType.METHOD, ElementType.ANNOTATION_TYPE๊ฐ€ ๋˜์–ด์žˆ๊ณ , @Component ์–ด๋…ธํ…Œ์ด์…˜์˜ docs๋ฅผ ๊ฐ€๋ณด๋ฉด ElementType.TYPE์œผ๋กœ ๋˜์–ด์žˆ๋‹ค.

๋”ฐ๋ผ์„œ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค์—๋Š” @Component๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ์—๋Š” ํ•ด๋‹น ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฉ”์†Œ๋“œ ์œ„์— @Bean์„ ์‚ฌ์šฉํ•œ๋‹ค.

๊ฐ„๋‹จํ•˜๊ฒŒ @Bean ์–ด๋…ธํ…Œ์ด์…˜์€ method ์œ„์— ๋ถ™์ผ ์ˆ˜ ์žˆ๊ณ , @Component ์–ด๋…ธํ…Œ์ด์…˜์€ class์œ„์— ๋ถ™์ผ ์ˆ˜ ์žˆ๋‹ค.

This post is licensed under CC BY 4.0 by the author.

์Šคํฌ๋Ÿผ ๊ธฐ๋ฒ•

AOP @Around ์–ด๋…ธํ…Œ์ด์…˜