Search
🌱

@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 ν•˜μ§€ μ•Šμ•˜λ‹€.
β€’
μ°Ύμ•„μ„œ 닀행이닀!