Arthur's Blog

Spring Bean์€ ์ƒํƒœ๋ฅผ ๊ฐ€์ ธ๋„ ๋˜๋Š”๊ฐ€? ๋ณธ๋ฌธ

Backend/Spring Boot

Spring Bean์€ ์ƒํƒœ๋ฅผ ๊ฐ€์ ธ๋„ ๋˜๋Š”๊ฐ€?

Leeseojune53 2023. 7. 1. 00:27

๐ŸŽŠ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์—..

EntryDSM์—์„œ Entry 6.0์„ ์ž‘์—…ํ•˜๋ฉด์„œ, ์ค‘๊ฐ„์— ์ƒ๊ฒผ๋˜ ์˜ค๋ฅ˜ ์ค‘ pdf ๋ฏธ๋ฆฌ๋ณด๊ธฐ์—์„œ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ์‚ฌ์ง„์ด ๋ณด์—ฌ์ง€๋Š” ํ˜„์ƒ์ด ์žˆ์—ˆ๋Š”๋ฐ QA๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์›์ธ์„ ์ฐพ์•˜๋‹ค.

ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์งง๊ฒŒ ๋ณด์ž๋ฉด

@Component
class PdfConverter {
    
    private final Map<String, Object> values = HashMap<>();
    
    ...
}
 

์™€ ๊ฐ™์€ ๊ตฌ์กฐ์˜€๋Š”๋ฐ Bean์€ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋ฉด ์•ˆ๋œ๋‹ค. ์œ„์˜ ์ฝ”๋“œ์—์„œ๋Š” Bean์ด ์‹ฑ๊ธ€ํ†ค์ด๋ฏ€๋กœ ์š”์ฒญ์ด ๋“ค์–ด์™€๋„ ์ด์ „์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์ด ์ƒํ™ฉ์—์„œ values๊นŒ์ง€ ๊ทธ๋Œ€๋กœ ์žˆ์—ˆ์œผ๋ฏ€๋กœ ๋ฎ์–ด์“ฐ๊ธฐ ๋˜์ง€ ์•Š๋Š” ๋ถ€๋ถ„์€ ์ด์ „ ์‚ฌ๋žŒ์˜ ๊ฐ’์ด ๋‚จ์•„์žˆ๋Š” ๊ฒƒ์ด์—ˆ๋‹ค. ๋”ฐ๋ผ์„œ Spring Bean์€ State lessํ•ด์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๊นจ๋‹ซ๊ณ  ์ด ๊ธ€์„ ์ž‘์„ฑํ•˜๊ฒŒ๋˜์—ˆ๋‹ค.

๐Ÿ“Œ Spring Bean์ด๋ž€?

Spring Bean์ด๋ž€ Spring IoC Container(Application Context)๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์ž๋ฐ” ๊ฐ์ฒด๋ฅผ Spring Bean์ด๋ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ˜ต Spring Bean์ด ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋ฉด ์•ˆ๋˜๋Š” ์ด์œ 

์œ„์—์„œ ์„œ์ˆ ํ–ˆ๋˜ ์˜ˆ์‹œ์ฒ˜๋Ÿผ ์ƒ๊ฐ์น˜ ๋ชปํ•œ ํฌ๋ฆฌํ‹ฐ์ปฌํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค, ๋˜ํ•œ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค๋ฉด Thread-Safeํ•˜์ง€ ์•Š๋Š”๋‹ค.

โ“ ์ƒํƒœ๊ฐ€ ๋ญ”๋ฐ?

๊ฐ’์ด ๋ณ€ํ•  ์ˆ˜ ์žˆ๋Š” ์ธ์Šคํ„ด์Šค ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒƒ.