KafkaBinderConfigurationProperties metadata

When generating configuration metadata (spring-configuration-metadata.json),
KafkaBinderConfigurationProperties class is missing all the information except
for the constructor bound KafkaProperties. We need to add the @Autowired on the
constructor so that Boot will not do a constructor binding and thus include all
the JavaBeans style properties in the metadata. See this Boot issue for more details.

https://github.com/spring-projects/spring-boot/issues/34031

In addition, this @Autowired is necessary for the properties to be correctly
bound when running in native mode.

Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2640
Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2644
This commit is contained in:
Soby Chacko
2023-02-07 18:16:23 -05:00
parent bde556a04b
commit 4100f27791
3 changed files with 84 additions and 4 deletions

View File

@@ -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;

View File

@@ -72,4 +72,69 @@
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -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