According to the @Conditional documentation:
If a @Configuration class is marked with @Conditional, all of the @Bean methods, @Import annotations,
and @ComponentScan annotations associated with that class will be subject to the conditions.
I believe that @PropertySource
in addition to @Bean
, @Import
, and @ComponentScan
is parsed by the ConfigurationClassParser which respects the condition as it processes the classes @Bean
methods, @Import
annotations, and @ComponentScan
annotations (at least @ComponentScan
explicitly by checking conditionEvaluator.shouldSkip
).
I think it would be intuitive for @PropertySource
to be subject to the @Conditional
condition of the class being processed as well.
Comment From: adase11
Apologies, I ran some tests and . @PropertySource
is indeed respected.
It may be useful to update the documentation of @Conditional
to reflect that.