How can I access properties loaded by <context:property-placeholder> in BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry.
I am unable to use fields annotated with @Value, as they do not seem to be initialized (their values are null).
Setting the value of fields annotated with
@Valuehappens only after the post-processing of theBeanDefinitionRegistry, meaning they are not usable at this stage of the initialization process.You can however explicitly scan the configuration environment and read the relevant properties' values from there, then use them in your dynamic bean definitions.
To gain access to the configuration environment, you can create your
BeanDefinitionRegistryPostProcessorin a method annotated with@Bean, that takes theConfigurableEnvironmentas a parameter.See the following example:
The sample code is adapted from this blog post, https://scanningpages.wordpress.com/2017/07/28/spring-dynamic-beans/