https://github.com/spring-projects/spring-boot/blob/b4c9bb0d5c1df4b4788ebbede69e125e559870e2/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java#L86

From what I can understand from the code, 1. @ConstructorBinding should be on @ConfigurationProperties only. Above method ensures that. 2. If there is @ConstructorBinding, BindingMethod becomes VALUE_OBJECT instead of JAVA_BEAN.

Now, when using @ConfigurationProperties with kotlin data object, we usually put @ConstructorBinding which makes BindingMethod.VALUE_OBJECT.

If we use ConfigurationProperties for Spring Cloud Bootstrap, it will go through ConfigurationPropertiesRebinder and try to rebind after application is loaded. Which, at that point, above method throws exception because the ConfigurationPropertiesBean's BindingMethod is VALUE_OBJECT.

I am uncertain whether this is bug or not when using it with Spring Cloud Bootstrap. Help would be much appreciated.

This is ConfigurationPropertiesBean's in kotlin i used for Bootstraping

@ConstructorBinding @ConfigurationProperties("flex.variant") data class FlexVariantProperties(val enabled: Boolean)

Comment From: wilkinsona

Thanks for the report. I don't think this problem is specific to Kotlin. Any constructor-bound configuration properties bean will be affected.

To support rebinding of immutable configuration properties beans, I think that Spring Cloud will have to proxy each bean so that the underlying instance can be replaced rather than attempting to rebind an existing instance. As you have observed, that rebinding isn't possible when the type is immutable.

Please open a Spring Cloud Commons issue with a minimal, ideally Java-based, sample that reproduces the problem and comment here with a link to it so that we can follow the problem. I recommend using Java as it will eliminate the possibility of the problem being specific to Kotlin and confirm my belief that it'll affect all immutable configuration properties bean.

Comment From: KirillKurdyukov

Hi, I have Ensure that @ConstructorBinding has not been applied to regular bean, when i try to have bean properties in bootstrap context and in application context. I have two @Configuration classes which inject Properties::class. I use Kotlin

Comment From: wilkinsona

@KirillKurdyukov Are you using Spring Cloud? If so, I think the same comment as I made above applies. It doesn't look like a Spring Cloud Commons issue was opened so you may like to open one. If you're not using Spring Cloud and you would like us to spend some more time investigating, please open a new issue providing a complete yet minimal sample that reproduces the problem. You can share the sample with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to the new issue.

Comment From: KirillKurdyukov

Sorry for the long answer :(

I have next case: Http client generated in application context but my config service in bootstrap context, because I use property source for load my configs in context. And I need a client for config service :)

I tried to solve the problem as follows:

spring.factories:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
ktor.client.core.configuration.KtorClientConfiguration

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
ktor.client.core.configuration.KtorClientBootstrapConfiguration

I make two klientBuilder's for bootstrap and application. Because objectMapper and meterRegistry, Brave configured in application context. Okey, config service don't need those beans. But KtorProperities I want from bootstrap.yaml and from application.yaml two beans.

@Configuration
@EnableConfigurationProperties(KtorClientsProperties::class)
class KtorClientBootstrapConfiguration

@Configuration
@EnableConfigurationProperties(KtorClientsProperties::class)
class KtorClientConfiguration

And I have this error

Caused by: java.lang.IllegalStateException: Cannot bind @ConfigurationProperties for bean 'ktor.client.core.configuration.KtorClientsProperties'. Ensure that @ConstructorBinding has not been applied to regular bean

But i delete @EnableConfigurationProperties(KtorClientsProperties::class) from KtorClientConfiguration, I have this error anyway :( Sorry, I have bad english (( Help me please! And strange for bean ObjectMapper from JacksonAutoConfiguration, need Spring mvc web why?)

Comment From: wilkinsona

@KirillKurdyukov We try to avoid using the issue tracker for questions and discussion like this as it creates a lot of noise for those watching the repository. Please follow up on Stack Overflow and include a minimal, reproducible example in your question.

Comment From: KirillKurdyukov

Okey!