When mapping YAML configuration using the class approach, there is no problem if you use the @Configuration annotation.
However, when switching to using record for mapping, Spring will inform you that it is a final type and cannot be proxied and managed in the container.
I have found that you can explicitly declare in the main class of Spring using @EnableConfigurationProperties(XXProperties.class) or @ConfigurationPropertiesScan that you need to add the class with the @ConfigurationProperties annotation to the container, regardless of whether it is a class or record.
In version 2.x of Spring Boot, if you want to use the record type to map YAML files, you need to add the annotation @ConstructorBinding to the class. However, in version 3.0 of Spring Boot, this is no longer necessary and it has been marked as deprecated.
https://youtrack.jetbrains.com/issue/IDEA-295483/Spring-Boot-ConfigurationProperties-annotated-java-record-is-reported-as-not-used
@SpringBootApplication
//@EnableConfigurationProperties(YmlConfigDbProperties.class)
@ConfigurationPropertiesScan
public class AppMain {
public static void main(String[] args) {
SpringApplication.run(AppMain.class, args);
}
}
@ConfigurationProperties(prefix = "config.db")
//@Configuration
public record YmlConfigDbProperties(){}