spring framework에서 특정 라이브러리 세팅을 라이브러리화 하기 위해서 wrapping을 하던 도중 일어난 일이다.
환경은 다음과 같다
목표
설정 파일은 다음과 같다.
https://github.com/pointware/client-test/blob/main/client/src/main/kotlin/com/example/clienttest/config/ClientProperties.kt
알게 된 점.
@EnableConfigurationProperties(ClientProperties::class) 를 적용해보았다.
@ConfigurationProperties 가 달려 있으면 된다.
@ConfigurationProperties 가 달린 bean은 이런 순서로 생성된다.
@Bean이 달린 method에서 생성 (beanFactory)
ConfigurationPropertiesBindingPostProcessor#postProcessBeforeInitialization
ConfigurationPropertiesBinder#bind
이것 때문에 properties 객체는 value로 생성하면 런타임에서 exception이 발생한다.
아무래도 reflection으로 하는건 아닌거 같고 setter를 원한다.
Failed to bind properties under 'message' to com.example.clienttest.config.ClientProperties:
Property: message.interval
Value: "99"
Origin: class path resource [application.properties] - 12:18
Reason: java.lang.IllegalStateException: No setter found for property: interval
Action:
Update your application's configuration
결론