Spring Boot 2.2.5

@SpringBootTest(classes = {
        MyConfigurationProperties.class,
        SomeConfiguration1.class,
        SomeConfiguration2.class,
})
@EnableConfigurationProperties
public class SomeTest {}

@Component
@ConfigurationProperties("app.some.prop1")
public class MyConfigurationProperties {
private String prop1;
// getter/setter
}

To resolve prop1 in MyConfigurationProperties I have to specify @EnableConfigurationProperties after @SpringBootTest excplicitly, why it's not autoconfigured?

If I start @SpringBootTest without classes parameter (which loads whole @SpringBootApplication context), prop1 is resolved without @EnableConfigurationProperties declaration after @SpringBootTest.

Comment From: mbhave

For @ConfigurationProperties to be registered as beans, you either need the @EnableConfigurationProperties annotation or configuration properties scanning using @ConfigurationPropertiesScan. Since you've specified the classes attribute, the class which has @SpringBootApplication (which I assume also has the @EnableConfigurationProperties annotation) will not be picked up. classes should be used for specifying configuration classes that should be used to load the application context and not for @ConfigurationProperties.

If you have any additional questions, please join us on Gitter or ask them on StackOverflow.

If you