KafkaBinderConfigurationProperties metadata

Remove @ConfigurationProperties from KafkaBinderConfigurationProperties
and move it to the respective @Bean methods in regular Kafka binder
and it's reactive counter part.

Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2640
This commit is contained in:
Soby Chacko
2023-03-07 17:26:47 -05:00
parent fba22efcb2
commit ce371f0bfb
3 changed files with 32 additions and 9 deletions

View File

@@ -38,7 +38,6 @@ import org.apache.kafka.clients.producer.ProducerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.stream.binder.HeaderMode;
import org.springframework.cloud.stream.binder.ProducerProperties;
import org.springframework.cloud.stream.binder.kafka.properties.KafkaProducerProperties.CompressionType;
@@ -64,7 +63,6 @@ import org.springframework.util.StringUtils;
* @author Chukwubuikem Ume-Ugwa
* @author Nico Heller
*/
@ConfigurationProperties(prefix = "spring.cloud.stream.kafka.binder")
public class KafkaBinderConfigurationProperties {
private static final String DEFAULT_KAFKA_CONNECTION_STRING = "localhost:9092";
@@ -146,14 +144,11 @@ public class KafkaBinderConfigurationProperties {
private boolean enableObservation;
/**
* @Autowired on this constructor is necessary in order to make sure that all the optional (provided as JavaBean setters)
* properties in this class are taken into consideration when generating configuration metadata.
* In addition, in order for all the properties to be discovered and bound when running as a native
* application, this @Autowired is necessary, so that Boot binding mechanism considers all the properties.
* See the following issues for more details.
* @Autowired on this constructor is necessary for all the properties to be discovered and bound when running as a native
* application.
*
* See the following issue for more details:
*
* https://github.com/spring-cloud/spring-cloud-stream/issues/2640
* https://github.com/spring-projects/spring-boot/issues/34031
* https://github.com/spring-cloud/spring-cloud-stream/issues/2644
*
* @param kafkaProperties Spring Kafka properties autoconfigured by Spring Boot

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.stream.binder.reactorkafka;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.kafka.properties.KafkaBinderConfigurationProperties;
@@ -41,7 +42,20 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties({ KafkaProperties.class, KafkaExtendedBindingProperties.class })
public class ReactorKafkaBinderConfiguration {
/**
* @ConfigurationProperties is declared on the @Bean method for Spring Boot to ignore
* constructor binding on KafkaBinderConfigurationProperties. If constructor binding is
* used, it ignores all the JavaBeans style properties when generating configuration metadata.
*
* See the following issues for more details:
*
* https://github.com/spring-cloud/spring-cloud-stream/issues/2640
* https://github.com/spring-projects/spring-boot/issues/34031
*
* @param kafkaProperties Spring Kafka properties autoconfigured by Spring Boot
*/
@Bean
@ConfigurationProperties(prefix = "spring.cloud.stream.kafka.binder")
KafkaBinderConfigurationProperties configurationProperties(
KafkaProperties kafkaProperties) {
return new KafkaBinderConfigurationProperties(kafkaProperties);

View File

@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.kafka.KafkaBinderMetrics;
@@ -90,7 +91,20 @@ import org.springframework.messaging.converter.MessageConverter;
@EnableConfigurationProperties({ KafkaProperties.class, KafkaExtendedBindingProperties.class })
public class KafkaBinderConfiguration {
/**
* @ConfigurationProperties is declared on the @Bean method for Spring Boot to ignore
* constructor binding on KafkaBinderConfigurationProperties. If constructor binding is
* used, it ignores all the JavaBeans style properties when generating configuration metadata.
*
* See the following issues for more details:
*
* https://github.com/spring-cloud/spring-cloud-stream/issues/2640
* https://github.com/spring-projects/spring-boot/issues/34031
*
* @param kafkaProperties Spring Kafka properties autoconfigured by Spring Boot
*/
@Bean
@ConfigurationProperties(prefix = "spring.cloud.stream.kafka.binder")
KafkaBinderConfigurationProperties configurationProperties(
KafkaProperties kafkaProperties) {
return new KafkaBinderConfigurationProperties(kafkaProperties);