spring boot v2.6.3

I notice that the ConfigurationProperties only worked for yaml if and only if the file name is application.yml.

I create a file under resources folder called aaa.properties. Inside contain the following

 oops.test=2

To detect this non-default properties file, i added @PropertySource({"classpath:aaa.properties"}) to the configuration annotated class.

So far everything works well. My ConfigurationProperties annotated class (with prefix oops) works as expected, that is its test field is indeed set to 2 when application run..

But when I rename it from app.properties to app.yml. The content changes to

oops: 
    test: 2

The @PropertySource,is changed to @PropertySource({"classpath:aaa.yml"})

The ConfigurationProperties annotated class now does not work anymore. That is, its test field is null when application run.

Is this a bug?

Comment From: snicoll

@PropertySource is a framework feature and does not support yaml.

To detect this non-default properties file

You don't have to use @PropertySource for that, Spring Boot has support for this with spring.config.import. Please review the documentation.