Hello!

I've this code

//@EnableConfigurationProperties(HttpClientConfig.class) // I've tried this as well with the same result
@ConfigurationPropertiesScan
@ConfigurationProperties(prefix = "http-client")
@Validated
public record HttpClientConfig(@Positive int connectTimeoutMs,
                               @Positive int readTimeoutSeconds,
                               @Positive int writeTimeoutSeconds,
                               @NotNull Retry retry) {
  public record Retry(@PositiveOrZero long maxAttempts,
                      @Min(200) @Max(1000) long minBackoffMs,
                      @Min(0) @Max(1) double jitterFactor) {
  }
}

I'm attempting to inject this type into another bean that requires these properties. (Not entirely sure how this is possible if the record itself isn't a bean --I assume the EnableConfigurationProperties does some magic there)

Startup is failing in several scenarios.

  1. On appstartup required a bean of type 'com.xxx.xxx.HttpClientConfig' that could not be found.

  2. During Integration tests I see 2 things -- When not using @Import(HttpClientConfig.class) , I see the same error above (no bean found) -- When using @Import(HttpClientConfig.class), I see 2 beans being created. One bean name i expect, and another I do not. the second bean name is using the prefix from the properties in its package name

No qualifying bean of type 'com.xxx.xxx.config.HttpClientConfig' available: expected single matching bean but found 2: com.xxx.xxx.config.HttpClientConfig,http-client-com.real.xxx.config.HttpClientConfig

I'm not entirely sure if this is my code issue, or if it's a Spring Boot issue -- I've never tried to use records for config props before.

Comment From: scottfrederick

Thanks for getting in touch. Instead of code snippets, please provide a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.

Comment From: therealaleko

@scottfrederick https://github.com/therealaleko/spring_boot_issue_37738

Comment From: scottfrederick

Thanks for the sample. The @EnableConfigurationProperties annotation must be applied to a @Configuration class, as mentioned in the documentation. The properties class (AppProperties in your example) is not a @Configuration class, so the annotation does not have any effect there. Moving the @EnableConfigurationProperties annotation from the AppProperties class to the SpringBootIssue37738Application class makes your sample work (because the @SpringBootApplication annotation is meta-annotated with @Configuration.

If you have any follow-up, please post a question to Stack Overflow.

Comment From: therealaleko

Thanks for the sample. The @EnableConfigurationProperties annotation must be applied to a @Configuration class, as mentioned in the documentation. The properties class (AppProperties in your example) is not a @Configuration class, so the annotation does not have any effect there. Moving the @EnableConfigurationProperties annotation from the AppProperties class to the SpringBootIssue37738Application class makes your sample work (because the @SpringBootApplication annotation is meta-annotated with @Configuration.

If you have any follow-up, please post a question to Stack Overflow.

Ah my bad. Thanks!