diff --git a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java index 96dad5fca..1b0a48cec 100644 --- a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java +++ b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.kafka.clients.consumer.ConsumerConfig; 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; @@ -144,6 +145,20 @@ 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. + * + * 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 + */ + @Autowired public KafkaBinderConfigurationProperties(KafkaProperties kafkaProperties) { Assert.notNull(kafkaProperties, "'kafkaProperties' cannot be null"); this.kafkaProperties = kafkaProperties; diff --git a/samples/kafka-binder-native-app/pom.xml b/samples/kafka-binder-native-app/pom.xml index 05439ce7e..29d177baa 100644 --- a/samples/kafka-binder-native-app/pom.xml +++ b/samples/kafka-binder-native-app/pom.xml @@ -72,4 +72,69 @@ + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + confluent + https://packages.confluent.io/maven/ + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/libs-release-local + + false + + + + + diff --git a/samples/kafka-binder-native-app/src/main/resources/application.yml b/samples/kafka-binder-native-app/src/main/resources/application.yml index d81c218ac..217c55d25 100644 --- a/samples/kafka-binder-native-app/src/main/resources/application.yml +++ b/samples/kafka-binder-native-app/src/main/resources/application.yml @@ -7,6 +7,6 @@ spring.cloud: destination: graalUppercaseFunction-in-0 graalLoggingConsumer-in-0: destination: graalUppercaseFunction-out-0 -spring: - kafka: - bootstrap-servers: localhost:9092 + kafka: + binder: + brokers: localhost:9092