I just upgraded spring boot libraries from version 3.0.8 to 3.1.1 and noticed that kafka clients were trying to connect to localhost:9092 instead of the correct Kafka bootstrap server configured in my application.properties file.

This is due to the fact that the class PropertiesKafkaConnectionDetails does not look into spring.kafka.properties or spring.kafka.consumer.properties when looking for the bootstrap server address. It relies only on properties KafkaProperties.bootstrapServers or KafkaProperties.Consumer.bootstrapServers

Example:

Application.java

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @KafkaListener(topics = "some-topic")
    void listen(String in) {
        System.out.println(in);
    }
}

application.properties

spring.kafka.properties.bootstrap.servers=some-broker-address-different-than-localhost:9093 # works fine in Spring Boot 3.0.8 

Comment From: scottfrederick

Duplicates #35694