I can't seem to get constructor binding to work for a properties file created with @ConfigurationProperties in my own auto-configuration module. The issue takes place using Spring Boot v3.1.2 with spring boot starter parent, Kotlin 1.9.0, JDK 17.

This properties file works perfectly when it is contained in the same maven module as the main module with the main class marked with @SpringBootApplication.

@ConfigurationProperties("eventsource.streams.aggregate")
data class KafkaStreamsProperties(
    val bootstrapServers: String,
    val applicationId: String,
    val eventTopic: String,
    val targetTopic: String
)

However, moving it into a separate library maven module with

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

and my org.springframework.boot.autoconfigure.AutoConfiguration.imports in resources.META-INF.spring contains no.holden.catalogs.libs.event.aggregate.KafkaStreamsProperties

I get met with Parameter 0 of constructor in no.holden.catalogs.libs.event.aggregate.KafkaStreamsProperties required a bean of type 'java.lang.String' that could not be found.

If I alter the class to have mutable fields with setters, it works as expected again e.g

@ConfigurationProperties("eventsource.streams.aggregate")
data class KafkaStreamsProperties(
    var bootstrapServers: String = "",
    var applicationId: String = "",
    var eventTopic: String = "",
    var targetTopic: String = ""
)

Comment From: mhalbritter

Hello. Configuration properties shouldn't be registered in org.springframework.boot.autoconfigure.AutoConfiguration.imports. The imports there point to the @AutoConfiguration annotated auto-configuration class. On this class you can then use @EnableConfigurationProperties(KafkaStreamsProperties.class).

Does this help?

If not, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: bentholden

Adding @EnableConfigurationProperties(KafkaStreamsProperties.class) to a configuration class and importing the configuration class instead works as expected, thanks :D