In my Spring Boot project (SB v2.4.4) I'm trying to conditionally enable a configuration class using @ConditionalOnProperty:
@ConditionalOnProperty(
value = "feature1.enabled",
havingValue = "true",
matchIfMissing = false
)
@Configuration
public class NewConfig {
...
}
Property feature1.enabled is declared in a features.properties file that is loaded using a second configuration class:
@Configuration
@PropertySource("classpath:features.properties")
public class FeaturesConfig {
}
Properties declared in features.properties are correctly loaded, but @ConditionalOnProperty doesn't seem to resolve feature1.enabled.
I also tried to annotate NewConfig class with a @DependsOn("featuresConfig"), but nothing changes.
The only thing that seems to work is to move feature1.enabled in application.properties.
So why this is not working? What's wrong with my configuration?
As suggested by M.Denium in his comment, I solved the issue adding this command line argument on application launch:
-Dspring.config.additional-location=classpath:/features.properties
adding features.properties file as an additional configuration location for my application, fixes the property resolution issue in @ConditionalOnProperty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With