Search
Duplicate
๐ŸŒฑ

@ConfigurationProperties ๋Š” ์–ธ์ œ ์ ์šฉ๋ ๊นŒ

๊ถ๊ธˆํ•œ ์ 

โ€ข
HikariConfig ๋ฅผ ๋‚ด๊ฐ€ ์„ค์ •ํ•œ ๋‚ด์šฉ์œผ๋กœ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•˜๊ณ ์ž ๋ฉ”์„œ๋“œ์— @Bean ์œผ๋กœ ๋“ฑ๋กํ•˜๋ ค๊ณ  ํ•˜์˜€๋‹ค.
โ€ข
@ConfigurationProperties ๋กœ ๋‚ด๊ฐ€ yaml ํŒŒ์ผ์— ์ ์€ ๋‚ด์šฉ์œผ๋กœ ํ•˜๋ ค๊ณ  ํ•˜์˜€๋‹ค.
โ€ข
๊ทธ๋Ÿฐ๋ฐ ์ด์ƒํ•˜๊ฒŒ ๋‚ด๊ฐ€ ํ•œ ๊ฒŒ ๋˜์ง€ ์•Š์•˜๋‹ค.
โ€ข
๊ทธ๋ž˜์„œ ์ž˜ ๋™์ž‘ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๊ฐ€์ ธ์™€์„œ ๋””๋ฒ„๊ทธ๋ฅผ ์ฐ์–ด๋ณด์•˜๋‹ค.
โ€ข
๋นˆ์„ ์ƒ์„ฑํ•  ๋•Œ์—๋Š” ์„ค์ • ๋‚ด์šฉ์ด ์ ์šฉ๋˜์ง€๋Š” ์•Š์•˜๋‹ค.

๊ณผ์ •

Config

โ€ข
new HikariConfig() ๋กœ return ํ•˜์˜€๋‹ค.

AbstractAutowireCapableBeanFactory

โ€ข
L:414 applyBeanPostProcessorsBeforeInitialization ๋ฉ”์„œ๋“œ
โ—ฆ
๋“ฑ๋ก๋œ beanPostProcessor ๋“ค์„ ๋ฐ˜๋ณต ๋Œ๋ฉด์„œ post processing ํ•œ๋‹ค.
โ—ฆ
17๊ฐœ๊ฐ€ ๋“ฑ๋ก๋˜์–ด์žˆ๋‹ค.

ConfigurationPropertiesBindingPostProcessor

โ€ข
๋‹ค๋ฅธ beanPostProcessor ๋“ค์€ ๋‹ค๋ฅธ ๋ฌธ์ œ์—†์ด ๊ธฐ์กด์˜ HikariConfig(์„ค์ •์ด ์ €์žฅ์ด ์•ˆ๋œ)๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค.
โ€ข
๊ทธ๋Ÿฌ๋‹ค๊ฐ€ ApplicationContextAwareProcessor ์—์„œ postProcessing ํ•˜๋‹ˆ BoundConfigurationProperties ๋กœ ๋ฐ”๋€Œ์—ˆ๋‹ค.
โ€ข
BoundConfigurationProperties ๋Š” ์•„๋งˆ ๋‚ด๊ฐ€ ์„ค์ •ํ•œ ๋‚ด์šฉ์ธ๋“ฏ
๋‚ด์ผ ๊ณต๋ถ€ํ•  ๊ฑฐ
โ€ข
์ฒ˜์Œ bean ์ด HikariConfig ์ผ ๋•Œ๋Š” ConfigurationPropertiesBindingPostProcessor ๋ฅผ ๊ฑฐ์น˜๋ฉด BoundConfigurationProperties ๊ฐ€ ๋œ๋‹ค.
โ€ข
BoundConfigurationProperties ๊ฐ€ ๋‹ค์‹œ 17๊ฐœ๋ฅผ ๋‹ค์‹œ ๋ˆ๋‹ค.
โ€ข
ConfigurationPropertiesBindingPostProcessor$postProcessBeforeInitialization ์—์„œ bind ํ•  ๋•Œ BoundConfigurationProperties ๋กœ ๋‹ค์‹œ ๋Œ๊ธฐ ์‹œ์ž‘ํ•œ๋‹ค.

JavaBeanBinder

โ€ข
L:82 bind ์—์„œ ํ•จ
โ€ข
ํƒ€๊ฒŸ(HikariConfig)์˜ field ๋ฅผ ๋Œ๋ฉด์„œ ๋ฐ”์ธ๋”ฉ ํ•  ํ”„๋กœํผํ‹ฐ๋“ค ์ฐพ์•„์„œ ๋ฐ”์ธ๋”ฉ

๋ฌธ์ œ ํ•ด๊ฒฐ

โ€ข
์ง„์งœ ์„ค์ • ๊ฐ’์„ ์ฐพ๋Š” ๋ถ€๋ถ„์€ Binder$findProperty(L:441)
โ€ข
source ๋“ค์„ ๋Œ๋ฉด์„œ(map ๋“ฑ๋“ฑ์ด ์žˆ๋‹ค) ์•Œ๋งž๋Š” ์†Œ์Šค๋กœ ๊ฐ’์„ ํ• ๋‹นํ•œ๋‹ค.
โ€ข
์•„๋‹ˆ๋ฉด yml์„ source ๋กœ ํ•ด์„œ ์ฐพ๋Š”๋‹ค.
โ€ข
๋ฌธ์ œ๊ฐ€ ๋ญ์˜€๋ƒ๋ฉด ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ์—์„œ ํ•ด๋‹น yaml ํŒŒ์ผ์„ import ํ•˜์ง€ ์•Š์•˜๋‹ค.
โ€ข
์ฐพ์•„์„œ ๋‹คํ–‰์ด๋‹ค!