In this example if you only change the boot version in the pom file and nothing else then the test goes from passing in 1.5.x to failing in 2.0.0.Mx:

https://github.com/ryandawsonuk/nest-map-spring-boot-config

As the example explains, the error is ConverterNotFoundException. It only happens when the file is referenced via TestPropertySource, not when application.yml in src/main/resources is used or even if an application.yml in src/test/resources is used.

Comment From: mbhave

@ryandawsonuk thanks for the sample.

@TestPropertySource seems like it is meant to be used with .properties files and not .yaml files. It treats the yaml file as a properties file and creates a source that has properties with keys activiti, cloud, user etc instead of a property with key activiti.cloud.user.bob.policy.read. In 1.5, it didn't throw an exception but it wasn't really using the properties from the TestPropertySource. Changing activiti.cloud.user.bob.policy.read to a different value in application.yml causes the test to fail. In 2.0, the new binder finds a property for activity with value "", tries to convert that to a ActivitiesProperty and fails with a conversion exception.

@snicoll Can you confirm that @TestPropertySource was not meant to be used with yaml files?

Comment From: snicoll

@PropertySource and TestPropertySource do not work with YAML indeed.

Comment From: mistriel

at least document it properly in the java doc ?

Yet i think its should be supported as its obvious for any spring user that YAML files are 1st class citizens !

Comment From: wilkinsona

@mistriel Both @PropertySource and TestPropertySource are part of Spring Framework rather than Spring Boot. If you would like to pursue your suggestion, please open a Spring Framework issue.

Comment From: mistriel

I see. Thanks for the clarification. Yet, IMHO a sibling boot annotation is expected WDYT ?

Comment From: wilkinsona

@mistriel Thanks for the suggestion, but I don't think adding a YAML-specific annotation to Spring Boot is the right solution here. If YAML support is going to be added then I think it should be added to Spring Framework. https://github.com/spring-projects/spring-framework/issues/18486 is tracking that. You may want to comment there to see if it can be re-opened or some amendments made to the javadoc.

Comment From: mistriel

@wilkinsona Thanks for the reference. I will try to push this in the other thread.

Comment From: mistriel

meanwhile i found a workaround: Use @SpringBootTest annotation and use classpath in your TestPropertySource:

@SpringBootTest
@TestPropertySource(properties = {"spring.config.location = classpath:test.yaml"})

Comment From: abhimanyuseth

I ended up using @PropertySource instead since it now supports a factory attribute. https://www.baeldung.com/spring-yaml-propertysource

@ExtendWith(SpringExtension::class)
@EnableConfigurationProperties(value = [ServiceConfigs::class])
@PropertySource("classpath:service-config-test.yml", factory = YamlPropertySourceFactory::class)

Comment From: madhur-grover

Thanks for the solutions mentioned in last two comments, but as mentioned in https://github.com/spring-projects/spring-boot/issues/10772#issuecomment-547383901, has there been any fix for this in the framework, as the issue is closed now?